The problem that I have, when I logged with normal user in the request.user 
there is a current user, but if I reload the page, the currennt user 
converted to the admin ?
Enter code here...
def countries_rate(request): 
auth_user = request.user
if request.user.is_authenticated:
auth_user = request.user
if (user_rate.objects.filter(user_id=auth_user).delete()):
print(auth_user,' OK deleted ----------------.................')
formset = countriesFormset(request.POST or None)
if request.method == 'POST':
if 'Add_More' in request.POST:
#print('--- add more in post -----')
cp = request.POST.copy()
cp['form-TOTAL_FORMS'] = int(cp['form-TOTAL_FORMS'])+ 1
formset = countriesFormset(cp,prefix='form')
total = cp['form-TOTAL_FORMS']
#print('total forms {}---------------------',format(total))
return render(request,'thesis_app/countries_rate.html', context={
'formset':formset,
'total':total
})
elif 'submit' in request.POST:
if formset.is_valid():
for inst in formset:
rate = user_rate()
if inst.is_valid():
#answer2 =inst.save(commit = False)
#answer2.user_id = auth_user
countries_name_id = inst.cleaned_data.get('countries_name_id')
country_rating = inst.cleaned_data.get('country_rating')
rate.user_id = auth_user
rate.countries_name_id = countries_name_id
rate.country_rating = country_rating
#print(auth_user,"................")
rate.save()
return redirect('thesis_app:result')
else:
return redirect('thesis_app:login') 
user = request.user
formset = countriesFormset(request.POST or None)
return render(request,'thesis_app/countries_rate.html', context={
'user':user,
'formset':formset
}
)


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/62ccddff-7c4d-4fb1-96d2-431c60f6b760%40googlegroups.com.

Reply via email to