fmartingr
/
shelfzilla
Archived
1
0
Fork 0
This repository has been archived on 2021-06-29. You can view files and clone it, but cannot push or open issues or pull requests.
shelfzilla/shelfzilla/models.py

32 lines
1.0 KiB
Python
Raw Permalink Normal View History

# coding: utf-8
# django
2014-03-18 15:54:01 +00:00
from django.db import models
from django.conf import settings
2014-03-18 15:54:01 +00:00
from django.utils.translation import ugettext_lazy as _
from django.template.defaultfilters import slugify
2014-03-18 15:54:01 +00:00
class Model(models.Model):
2014-03-18 15:54:01 +00:00
for_review = models.BooleanField(_('For review'), default=False)
added_by = models.ForeignKey(settings.AUTH_USER_MODEL,
null=True, blank=True)
2014-03-26 11:24:11 +00:00
for_review_comment = models.TextField(
_('Review comment'), null=True, blank=True)
2014-03-18 15:54:01 +00:00
hidden = models.BooleanField(_('Hidden'), default=False)
def first_letter(self):
if hasattr(self, 'name'):
return self.name and self.name[0] or ''
def save(self, *args, **kwargs):
# If model have a name and slug attribute, save slug
# TODO set a model field to custom field name for slug creation
if not getattr(self, 'slug', None) and getattr(self, 'name', None):
self.slug = slugify(self.name)
return super(Model, self).save(*args, **kwargs)
2014-03-18 15:54:01 +00:00
class Meta:
abstract = True