在外键连接本表与另一个表时,有点烦,p26需要再研究一下

app01/models.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
from django.db import models
from account.models import User
from utils.basemodels import BaseModel
# Create your models here.
class Article(BaseModel):
id = models.AutoField(primary_key=True)
title = models.CharField(max_length=120)
slug = models.CharField(max_length=200, default='')
content = models.TextField()
publish_date = models.DateTimeField()
user = models.ForeignKey(User, on_delete=models.CASCADE)

class Meta:
db_table = 'article'
verbose_name = '文章信息'
verbose_name_plural = '文章信息'
ordering = ['-publish_date']

account/models.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import email
from pickle import TRUE
from django.db import models
from utils.basemodels import BaseModel
# Create your models here.
class User(BaseModel):
id = models.AutoField(primary_key=True)
username = models.CharField('用户名', max_length=30,null=True,blank=True,unique=True)
password = models.CharField('密码',max_length=30)
email = models.EmailField('邮箱', null=True,blank=True, unique=True)

class Meta:
db_table = 'user'
verbose_name = '用户信息'
verbose_name_plural = '用户信息'