Advertisement
Guest User

Untitled

a guest
Aug 31st, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from django.conf import settings
  2. from django.db import models
  3. from django.utils.translation import ugettext as _
  4.  
  5.  
  6. # Move timestampable to a separate behaviors.py file
  7. class Timestampable(models.Model):
  8.     """Abstract base class that provides auto-updating created and modified timestamps"""
  9.     created = models.DateTimeField(_('Created'), auto_now_add=True, db_index=True, help_text=_('Created timestamp'))
  10.     modified = models.DateTimeField(_('Modified'), auto_now=True, db_index=True, help_text=_('Last modified timestamp'))
  11.  
  12.     class Meta:
  13.         abstract = True
  14.  
  15.  
  16. class Category(Timestampable, models.Model):
  17.     """Comment about the purpose of this model"""
  18.     name = models.CharField(_('Name'), max_length=25, db_index=True, help_text=_('The name of the category'))
  19.     submit_date = models.DateTimeField(_('Submitted'), editable=False, help_text=_('When the category was submitted'))
  20.     edit_date = models.DateTimeField(_('Editted'), editable=True, help_text=_('The last time the category was editted'))
  21.  
  22.     submit_user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
  23.     edit_user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
  24.    
  25.     # Custom manager: https://docs.djangoproject.com/en/1.10/topics/db/managers/#from-queryset
  26.     # objects = managers.CategoryManager.from_queryset(querysets.CategoryQueryset)()
  27.  
  28.     class Meta:
  29.         verbose_name = _('Category')
  30.         verbose_name_plural = _('Categories')
  31.  
  32.     def __str__(self):
  33.         return self.name
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement