Guest User

Untitled

a guest
Jul 31st, 2015
314
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     from django.http import HttpResponse
  2.     from django.utils.encoding import python_2_unicode_compatible
  3.  
  4.  
  5.     def cabinet(request, user_id):
  6.         user = User.objects.filter(id=user_id).first()
  7.         if user and user.is_authenticated():
  8.             profile = Profile.objects.get_or_create(user=user_id)
  9.         else:
  10.             return HttpResponse("Авторизуйтесь")
  11.         return render(request, 'cabinet.html', {'profile': profile})
  12.  
  13.  
  14.     @python_2_unicode_compatible
  15.     class Profile(models.Model):
  16.         user = models.OneToOneFielde(User)
  17.         phone_number = models.CharField(max_length=10, blank=True)
  18.         first_name = models.CharField(max_length=120, blank=True)
  19.         last_name = models.CharField(max_length=120, blank=True)
  20.         avatar = models.FileField(upload_to='media/images/', blank=True, null=True)
  21.  
  22.         def __str__(self):
  23.             return self.user
RAW Paste Data