- Under the framework of using the django comes with User auth.models be extended to increase the field - TTT breeze Week - blog Park
- 2019-05-09 14:51:11 Source: TTT Week breeze
- Favorites I want to contribute
Django using the built-in frame auth.models User extended field increases
We need to change three places:
1.models.py create a model User, and inherits the original model class AbstraUser (where I added a new field phone number)
1
2
3
4
5
6
7
8
9
10
|
from django.db
import
models
# Create your models here.
from django.contrib.auth.models
import
AbstractUser
class
User(AbstractUser):
tel = models.CharField(max_length=
11
, unique=False, verbose_name=
'手机号'
)
|
2.settings.py new settings are as follows, 'first_app' is the name of your app, 'User' class name in Step 1 models.py newly created (that is, the new table name, from here still use the original with the table name)
1
2
|
# 继承原User表设置
AUTH_USER_MODEL =
'first_app.User'
|
3. where there is a pit, most of the blog did not write this step, such as code, commented out before we use the User class User frame comes when imported, and imported models from the current directory in the User only User is we use the extension, because the original has been replaced after User inherited, do not change here will complain:
error:Manager isn't available; 'auth.User' has been swapped for 'first_app.User' in Django
1
2
|
# from django.contrib.auth.models
import
User
from .models
import
User
|
End, or do not know if any other opinion welcome to add my micro letter exchange: zhx799758765