Answer the question
In order to leave comments, you need to log in
How do I fill out a profile/update a profile when available?
Hello.
The situation is this:
There is a user profile, where there is additional information (Avatar, about myself, what I offer).
Task: to make a profile filling form that would accept fields (not necessarily all), and update them (not necessarily all).
class Profile_Form(forms.Form):
avatar = forms.ImageField(label='Загрузить Аватар', required=False)
myself = forms.CharField(widget=forms.Textarea(attrs={'class': 'course_review_form_width'}), label='О себе', required=False)
myoffer = forms.CharField(widget=forms.Textarea(attrs={'class': 'course_review_form_width'}), label='Что предлагаю', required=False)
def update_profile(request, add_id):
token = {}
token.update(csrf(request))
if request.user.is_authenticated():
current_user = request.user
if request.POST:
# profilepage = Profile.objects.get(id = add_id)
form = Profile_Form(request.POST or None, request.FILES or None)
if form.is_valid():
avatar = form.cleaned_data['avatar']
myself = form.cleaned_data['myself']
myoffer = form.cleaned_data['myoffer']
profile_obj = Profile(user=current_user, avatar=avatar, myself=myself, myoffer = myoffer)
profile_obj.save()
return redirect('/profile'+ add_id, token)
else:
return redirect('/profile'+ add_id, token)
else:
return redirect('/profile'+ add_id, token)
else:
return redirect('/profile'+ add_id, token)
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