What Way is best to extend User in Django 1.11?

69 views
Skip to first unread message

李余通

unread,
Jul 18, 2017, 2:48:28 AM7/18/17
to Django users
How to extend User?I find many ways;
1. Use Profile
eg:
class UserProfile(models.Model):
    user = models.OneToOneField(User)    
    major = models.TextField(default='', blank=True)

This way is easy to understand,However,it will create a new table in sql,I heard this will add System burden.

2.inherit User
eg:
class CustomUser(User): timezone = models.CharField(max_length=50, default='Asia/shanghai') objects = UserManager()

This way seems also will add a new table.

There also have some way but i don't understand,so I want know on Django 1.11,What way is best to extend User?

Avraham Serour

unread,
Jul 18, 2017, 9:37:29 AM7/18/17
to django-users
I suggest creating a profile, leave the auth.User only for auth, all else specific to you application use your own model and reference to that


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ee6c8e4a-5f0a-4d20-9855-6c4af4792ff8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

James Bennett

unread,
Jul 18, 2017, 10:01:57 AM7/18/17
to django...@googlegroups.com
If the fields you're adding are things that you need to know for purposes of figuring out who someone is and what they're allowed to do, put them in a custom User model.

If the fields you're adding are not for the purpose of figuring out who someone is and what they're allowed to do, put them in a related profile model.
Reply all
Reply to author
Forward
0 new messages