Answer the question
In order to leave comments, you need to log in
How to take value in view?
Hello everyone, what sections to read in the documentation?
there is a model, a form and a view.
set the foreign key in the model
user = models.ForeignKey(settings.AUTH_USER_MODEL,blank=True)
the user is authorized, how can I check it in the view? , I can have only one entry in the database with the form attached to a specific user. if the user has already filled out the form, then the form to fill out is not displayed to him, and if it is filled out, then there is a redirect to the profile page.
maybe someone will throw off links what to read specifically or just tell.
def user_data(request):
if request.method == "POST":
form = UserDataForm(request.POST)
if form.is_valid():
#уставливает связь сохраняемой формы с авторизованным юзером
form.instance.user = request.user
print(request.user)
form.save()
return redirect('/')
else:
form=UserDataForm()
return render(request,'myoffice/userdata.html',{'form':form})
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question