Devinwon / article

0 stars 0 forks source link

Inherit model #22

Open Devinwon opened 6 years ago

Devinwon commented 6 years ago

models.py

注意不要与系统自带的重复了

class User(AbstractUser):
    nickName=models.CharField(max_length=128)
    userImage=models.ImageField(upload_to="userProfile/image",default='userProfile/image/default.jpg',max_length=300,blank=True,null=True)
    cellphone=models.CharField(max_length=11)

Example of an abstract model

from django.db import models
class BaseContent(models.Model):
title=models.CharField(max_length=100)
created=models.DateTimeField(auto_now_add=True)
class Meta:
abstract=True
class Text(BaseContent):
body=models.TextField()

settings.py

注册,login为app名字,User为models.py中的名字

AUTH_USER_MODEL = 'login.User'

django 2.0适用

`

注意替换,否则无效

`

from django.contrib.auth.models import User

` from .models import User