def new(request): # print("---- new ----") # print("request.GET = {}".format(request.GET)) # print("request.POST = {}".format(request.POST)) # print("request.FILES = {}".format(request.FILES)) lat = request.GET.get('lat', None) lng = request.GET.get('lng', None) if lat and lng: lnglat = '{},{}'.format(lng, lat) else: lnglat = None if request.method == 'POST': form = PostForm(request.POST, request.FILES) if form.is_valid(): # title = form.cleaned_data['title'] # content = form.cleaned_data['content'] # photo = form.cleaned_data['photo'] # post = Post(title=title, content=content, photo=photo) form.save() messages.info(request, '새 포스팅!') return redirect('mymap:index') else: form = PostForm(initial={'lnglat': lnglat}) return render(request, "mymap/form.html", { 'form': form, })
def pt_add(request): rt = '' if request.method == 'POST': pfm = PostForm(request.POST) if pfm.is_valid() and pfm.cleaned_data['post_id'] == '0': rt = u_post_add(pfm, request) else: u_post_update(pfm, request) rt = pfm.cleaned_data['post_mid'] return HttpResponseRedirect("/do_editor?id=" + str(rt))
def edit(request, pk): post = get_object_or_404(Post, pk=pk) if request.method == 'POST': form = PostForm(request.POST, request.FILES, instance=post) if form.is_valid: form.save() return redirect('mymap:index') else: form = PostForm(instance=post) return render(request, 'mymap/form.html', { 'form': form, })