Django version:1.7.1
The simplest of recommendations:
Expand Fields with Abstractuser
Copy the Code code as follows:
profiles/models.py
From django.db import Models
From Django.contrib.auth.models import Abstractuser
From django.utils.translation import Ugettext_lazy as _
# Create your models here.
Class Karmauser (Abstractuser):
Karma = models. Positiveintegerfield (_ ("Karma"), Default=0,blank=true)
settings.py
Auth_user_model = ' profiles. Karmauser '
2. Using Abstractbaseuser
Only when you are on the user
The default field in the model is not used until it is satisfied, this method only retains the passwork,last_login,is_active three fields
Refer to the official documentation:
https://docs.djangoproject.com/en/1.7/topics/auth/customizing/
3. Use a one-to-one relationship to link related models together
This is much like the way Django 1.5 was. Ideal for creating third-party expansion package scenarios, loosely coupled without destroying the structure of the previous project.
Scenarios where this method is required:
-In your own Django PRJ, you want multiple users to have very different fields. You might want some users to combine some type of user field and want to be able to solve these problems at the model level.
Examples are as follows:
profiles/models.py
Copy the Code code as follows:
From django.conf Import settings
From django.db import Models
From Flavors.models import Flavor
Class Eaterprofile (models. Model):
# Default User profile
user = models. Onetoonefield (settings. Auth_user_model)
Favorite_ice_cream = models. ForeignKey (Flavor,null=true,blank=true)
Class Scooperprofile (models. Model):
user = models. Onetoonefield (settings. Auth_user_model)
scoops_scooped = models. Integerfield (default=0)
Class Inventorprofile (models. Model):
user = models. Onetoonefield (settings. Auth_user_model)
flavors_invented = models. Manytomanyfield (Flavor,null=true,blank=true)
Personally, I think the second is the most appropriate in my site. Testing whether the model can be simplified with abstract classes. To be Continued ...
The above 3 kinds of methods have advantages and disadvantages, everyone according to their own needs, free choice bar.