Skip to content

Instantly share code, notes, and snippets.

@phalt
Created September 7, 2017 09:00
Show Gist options
  • Save phalt/6f5e45a3dc9a308e1f4708fd48ce35c2 to your computer and use it in GitHub Desktop.
Save phalt/6f5e45a3dc9a308e1f4708fd48ce35c2 to your computer and use it in GitHub Desktop.
Abstract Base models
from django.db import models
class DateTimeModel(models.Model):
class Meta:
abstract = True
date_created = models.DateTimeField(auto_now_add=True)
date_updated = models.DateTimeField(auto_now=True)
from abstract import DateTimeModel
class MyModel(DateTimeModel):
foo = models.CharField()
'''
This model above will have date_created and date_updated added to it!
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment