标签:管理 出现 nat 脏数据 重构 auth models 序列化 rac
为抽象表,是专门用来被继承,提供公有字段的,自身不会完成数据库迁移
class BaseModel(models.Model):
is_delete = models.BooleanField(default=False)
created_time = models.DateTimeField(auto_now_add=True)
class Meta:
abstract = True
class Book(BaseModel):
name = models.CharField(max_length=64)
price = models.DecimalField(max_digits=10, decimal_places=2)
publish = models.ForeignKey(to='Publish', related_name='books', db_constraint=False, on_delete=models.DO_NOTHING, null=True)
authors = models.ManyToManyField(to='Author', related_name='books', db_constraint=False)
def __str__(self):
return self.name
class Publish(BaseModel):
name = models.CharField(max_length=64)
address = models.CharField(max_length=64)
class Author(BaseModel):
name = models.CharField(max_length=64)
class AuthorDetail(BaseModel):
mobile = models.CharField(max_length=64)
author = models.OneToOneField(to=Author, related_name='detail', db_constraint=False, on_delete=models.CASCADE)
标签:管理 出现 nat 脏数据 重构 auth models 序列化 rac
原文地址:https://www.cnblogs.com/shenblog/p/12103854.html