reload the page and the logged in user converted to the admin

5 views
Skip to first unread message

ayoub ELMAJJODI

unread,
Aug 24, 2019, 3:13:30 PM8/24/19
to Django users
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
}
)


N'BE SORO

unread,
Aug 24, 2019, 7:26:45 PM8/24/19
to django...@googlegroups.com
Hello, 
Use Django login function 



--
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...@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.

James Schneider

unread,
Aug 24, 2019, 8:19:06 PM8/24/19
to django...@googlegroups.com

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)


Not sure if it's related, but is there a reason you immediately delete the logged-in user as soon as the page loads? Even before any forms are submitted?

-James
Reply all
Reply to author
Forward
0 new messages