X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/7e94b10a9875ce8b4d7d109606cdac85b0ab831d..cbb14d2ed3eb0b72a6c3c68ab93847923e6142f4:/apps/wiki/models.py diff --git a/apps/wiki/models.py b/apps/wiki/models.py index a3b952a0..a9264934 100644 --- a/apps/wiki/models.py +++ b/apps/wiki/models.py @@ -13,14 +13,36 @@ import logging logger = logging.getLogger("fnp.wiki") -class Document(models.Model): +class Book(models.Model): """ A document edited on the wiki """ - slug = models.CharField(_('slug')) - title = models.CharField(_('displayed title'), blank=True) - data = models.ForeignKey(dvcs_models.Document) - gallery = models.CharField(_('scan gallery name'), blank=True) + slug = models.SlugField(_('slug'), max_length=255, unique=True) + title = models.CharField(_('displayed title'), max_length=255, blank=True) + doc = models.ForeignKey(dvcs_models.Document, editable=False) + gallery = models.CharField(_('scan gallery name'), max_length=255, blank=True) + class Meta: + ordering = ['title'] + verbose_name = _('book') + verbose_name_plural = _('books') + + def __unicode__(self): + return self.title + + @classmethod + def create(cls, creator=None, text=u'', *args, **kwargs): + instance = cls(*args, **kwargs) + instance.doc = dvcs_models.Document.create(creator=creator, text=text) + instance.save() + return instance + + @staticmethod + def listener_create(sender, instance, created, **kwargs): + if created and instance.doc is None: + instance.doc = dvcs_models.Document.objects.create() + instance.save() + +models.signals.post_save.connect(Book.listener_create, sender=Book)