Django version:1.7.1
The simplest recommendation:
use Abstractuser to expand fields
Copy 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. Use of Abstractbaseuser
Only when you're on the user
Model inside the default field when you want to use, this method only retains the passwork,last_login,is_active three fields
Refer to official Documentation:
https://docs.djangoproject.com/en/1.7/topics/auth/customizing/
3. Use one-to-one relationships to link related models together
It's much like the way Django was before 1.5. It is ideal for creating third-party expansion packs, loosely coupled, without disrupting the structure of previous projects.
Scenarios that require this method:
-Under your Django PRJ, you want multiple users to have fields that are very different. You may want to combine some of the user's type fields and hope to solve them at the model level.
Examples are as follows:
profiles/models.py
Copy 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 think that in my site, the second most appropriate. 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.