Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Profile(models.Model):
- user = models.OneToOneField(User, on_delete=models.CASCADE)
- bio = models.TextField(max_length=500, blank=True)
- location = models.CharField(max_length=30, blank=True)
- birth_date = models.DateField(null=True, blank=True)
- email_confirmed = models.BooleanField(default=False)
- image= models.ImageField(upload_to='profile_image', blank=True)
- def __str__(self):
- return self.user.username
- class ProfileUpdateForm(forms.ModelForm):
- YEARS= [x for x in range(1900,2021)]
- birth_date = forms.DateField( initial="21-06-1995", widget=forms.SelectDateWidget(years=YEARS))
- image = models.ImageField(upload_to='profile_image',blank=True)
- class Meta:
- model = Profile
- fields = ('bio','birth_date','location','image')
- @login_required
- def profile_edit(request):
- form = ProfileUpdateForm(request.POST)
- if request.method == 'POST':
- if form.is_valid():
- user = request.user
- user.profile.bio = form.cleaned_data.get("bio")
- user.profile.birth_date = form.cleaned_data.get("birth_date")
- user.profile.location = form.cleaned_data.get("location")
- user.save()
- return redirect('profile')
- else:
- form = ProfileUpdateForm()
- context = {
- 'form' : form
- }
- return render(request, 'webside/profile_edit.html', context)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement