Created
October 19, 2017 04:58
-
-
Save MerleLiuKun/ef14bb9854a54f27aa35d7b1df4857d0 to your computer and use it in GitHub Desktop.
django abstract model demo.
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 AbstractTimeModel(models.Model): | |
""" | |
Simple abstract base class. | |
provide the general created time, update time fields. | |
可以将 公用的字段抽取出来. | |
""" | |
created_at = models.DateTimeField( | |
verbose_name="创建时间", | |
auto_now_add=True, | |
) | |
updated_at = models.DateTimeField( | |
verbose_name="更新时间", | |
auto_now=True, | |
) | |
class Meta: | |
abstract = True | |
class Article(AbstractTimeModel): | |
title = models.CharField( | |
max_length=200, | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment