So I have this new Problem where I submit data into on form and redirect to another form.
in the Forms.py file of the second form I use a queryset function to fetch the last data from the model that I filled just in the first form .
This is not happening for me and the data I get is the last entry that was already in the model before I refreshed the server
I want the second form to fetch the latest entry without refreshing or restarting the server
Below is the Code for the Two forms
First Form
d1s1choice = []
plnm = day1.objects.values_list('d1sight' , flat= True).last()
print(plnm)
z = place.objects.all()
for x in z:
# y = "('" + x.placeName + "',)"
y = x.placeName
if plnm == y:
print (plnm + y)
d1s1choice.append((x.point1,x.point1))
View
@login_required
def bday1(request):
q = request.session['qs']
nquery = q + 1
day = 1
formd1 = buildday1(request.POST or None, request.FILES or None)
place_obj = place.objects.all()
content ={
"query" : q,
"nquery" : nquery,
"formd1" : formd1,
"place_obj" : place_obj,
"day": day
}
if day != q:
if formd1.is_valid():
print (request.POST)
formd1.save()
x = formd1.cleaned_data['code']
content['formd1'] = buildday1()
request.session['x']=x
return redirect("/itnry/buildd1s")
return render(request, "itnry/buildday1.html", context=content)
@login_required
def bd1s1(request):
q = request.session['qs']
x = request.session['x']
nquery = q + 1
day = 1
initiald1s = {'code': x}
formd1s = buildday1s(request.POST or None, request.FILES or None, initial= initiald1s)
place_obj = place.objects.all()
content ={
"query" : q,
"nquery" : nquery,
"formd1s" : formd1s,
"place_obj" : place_obj,
"x": x,
"day": day
}
if day != q:
if formd1s.is_valid():
print (request.POST)
formd1s.save()
content['formd1s'] = buildday1s()
return redirect("itnry/buildday2.html")
return render(request, "itnry/buildd1s.html", context=content)