Hi,
I'm starting a new project and for the first time I need to extend the User 
model.
I read the documentation and I googled a lot to try to figure out what is 
the best approach but I got confused.

What's the the best approach?

Class inheritance:

from django.contrib.gis.db import models
from django.contrib.auth.models import User, UserManager

class myUser(User):
    birthday = models.DateField(null=True, blank=True)
    address = models.CharField(max_length=255, null=True, blank=True)
    
    objects = UserManager()

Or OneToOneField (as doc suggests)


from django.contrib.gis.db import models
from django.contrib.auth.models import User
from django.db.models.signals import post_save

class myUser(User):
    user = models.OneToOneField(User)
    birthday = models.DateField(null=True, blank=True)
    address = models.CharField(max_length=255, null=True, blank=True)

    def __unicode__(self):
          return u'%s' % self.user

def create_user_profile(sender, instance, created, **kwargs):
    if created:
        myUser.objects.create(user=instance)

post_save.connect(create_user_profile, sender=User)

Thanks,

Alex

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/KtEPwiHoWbUJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to