Skip to content

Instantly share code, notes, and snippets.

@MerleLiuKun
Created October 19, 2017 04:58
Show Gist options
  • Save MerleLiuKun/ef14bb9854a54f27aa35d7b1df4857d0 to your computer and use it in GitHub Desktop.
Save MerleLiuKun/ef14bb9854a54f27aa35d7b1df4857d0 to your computer and use it in GitHub Desktop.
django abstract model demo.
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