daily pastebin goal
75%
SHARE
TWEET

Untitled

a guest Mar 20th, 2019 43 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Profile(models.Model):
  2. user = models.OneToOneField(User, on_delete=models.CASCADE)
  3. bio = models.TextField(max_length=500, blank=True)
  4. location = models.CharField(max_length=30, blank=True)
  5. birth_date = models.DateField(null=True, blank=True)
  6. email_confirmed = models.BooleanField(default=False)
  7. image= models.ImageField(upload_to='profile_image', blank=True)
  8.  
  9. def __str__(self):
  10.     return self.user.username
  11.      
  12. class ProfileUpdateForm(forms.ModelForm):
  13. YEARS= [x for x in range(1900,2021)]
  14. birth_date = forms.DateField( initial="21-06-1995", widget=forms.SelectDateWidget(years=YEARS))
  15. image = models.ImageField(upload_to='profile_image',blank=True)
  16. class Meta:
  17.     model = Profile
  18.     fields = ('bio','birth_date','location','image')
  19.      
  20. @login_required
  21. def profile_edit(request):
  22. form = ProfileUpdateForm(request.POST)
  23.  
  24. if request.method == 'POST':
  25.  
  26.     if form.is_valid():
  27.         user = request.user
  28.         user.profile.bio = form.cleaned_data.get("bio")
  29.         user.profile.birth_date = form.cleaned_data.get("birth_date")
  30.         user.profile.location = form.cleaned_data.get("location")
  31.         user.save()
  32.         return redirect('profile')
  33.     else:
  34.         form = ProfileUpdateForm()
  35.  
  36. context = {
  37.     'form' : form
  38.  
  39. }
  40. return render(request, 'webside/profile_edit.html', context)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top