Last active
November 1, 2018 09:29
-
-
Save mayneyao/c2346c85b31eb140f6538af54dc9302b to your computer and use it in GitHub Desktop.
django 通用模型
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
class CommonModel(models.Model): | |
create_time = models.DateTimeField(verbose_name='创建时间', auto_now_add=True, blank=True) | |
update_time = models.DateTimeField(verbose_name='更新时间', auto_now=True, blank=True) | |
active = models.NullBooleanField(verbose_name='是否有效', default=True, blank=True) | |
class Meta: | |
abstract = True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
通用的业务单据有很多字段是重复的,每次建模型的时候都重复的定义这些字段比较繁琐。
好的解决方案是,使用django的抽象基类。
实际的业务模型继承这个模型,就可以获得通用字段。