def addpost(request): print("you hit add post") if request.method == 'POST': print("got post request") title = request.POST.get("title", "") description = request.POST.get("description", "") rentperday = request.POST.get("rentperday", "") facilities = request.POST.getlist("facilities") print(facilities) if facilities is not None: facilities = ",".join(facilities) else: facilities = "" address = request.POST.get("address", "") street = request.POST.get("street", "") city = request.POST.get("city", "") pincode = request.POST.get("pincode", "") state = request.POST.get("state", "") country = request.POST.get("country", "") deposit = request.POST.get("deposit", "") guests = request.POST.get("guests", "") house_type = request.POST.get("house_type", "") accom_type = request.POST.get("accom_type", "") accom_for = request.POST.getlist("accom_for") if accom_for is not None: accom_for = ",".join(accom_for) else: accom_for = "" print(deposit, guests, house_type, accom_type, accom_for) p = Post() p.description = description p.title = title p.user = request.user p.rentperday = rentperday p.facilities = facilities p.address = address p.street = street p.city = city p.pincode = pincode p.state = state p.country = country p.deposit = deposit p.guests = guests p.housetype = house_type p.accom_type = accom_type p.accom_for = accom_for p.save() if request.FILES.getlist("photos"): print(request.FILES.getlist("photos")) for f in request.FILES.getlist("photos"): print(f) image = PostPhoto() image.photo = f image.post = p image.save() return HttpResponseRedirect( "/addpost/?msg=susscessfully added property&id=" + str(p.id)) else: context = {} postid = request.GET.get("id", "") if postid: post = Post.objects.get(id=postid) context["post"] = post context["msg"] = request.GET.get("msg", "") return render(request, 'addpost.html', context)