View

extender auth_user django modificando campos — (aplicando herencia)

  1. #1
  2. from django.db import models
  3. from django.contrib.auth.models import User, UserManager
  4. class CustomUser(User):
  5.     birthday = models.DateField()
  6.     activation_key = models.CharField(max_length=255, blank=True, default=)
  7.     photo_url = models.CharField(max_length=50, blank=True) # cant incrementada de votaciones
  8.     User._meta.get_field(‘username’)._unique = False
  9.     User._meta.get_field(’email’)._unique = True
  10.     User._meta.get_field_by_name(‘username’)[0].max_length=75
  11. #2 save child class
  12. from users.models import CustomUser
  13. def saveCustomUsers(request):
  14.     usr = CustomUser()
  15.     usr.username = ‘macks’
  16.     usr.password = ‘123456’
  17.     usr.activation_key = ‘sfsdf123456’
  18.     usr.birthday = datetime.now()
  19.     usr.photo_url = ‘image.jpg’
  20.     usr.save()

You may also like