1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
"""
This is more a proof-of-concept for your own :class:`feincms.module.Base`
subclasses than a polished or even sufficient blog module implementation.
It does work, though.
"""
from django.db import models
from django.db.models import signals
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
from feincms.admin import item_editor
from feincms.management.checker import check_database_schema
from feincms.models import Base
class EntryManager(models.Manager):
def published(self):
return self.filter(
published=True,
published_on__isnull=False,
published_on__lte=timezone.now(),
)
class Entry(Base):
published = models.BooleanField(_('published'), default=False)
title = models.CharField(_('title'), max_length=100,
help_text=_('This is used for the generated navigation too.'))
slug = models.SlugField()
published_on = models.DateTimeField(_('published on'), blank=True, null=True,
help_text=_('Will be set automatically once you tick the `published` checkbox above.'))
class Meta:
get_latest_by = 'published_on'
ordering = ['-published_on']
verbose_name = _('entry')
verbose_name_plural = _('entries')
objects = EntryManager()
def __unicode__(self):
return self.title
def save(self, *args, **kwargs):
if self.published and not self.published_on:
self.published_on = timezone.now()
super(Entry, self).save(*args, **kwargs)
@models.permalink
def get_absolute_url(self):
return ('blog_entry_detail', (self.id,), {})
@classmethod
def register_extension(cls, register_fn):
register_fn(cls, EntryAdmin)
signals.post_syncdb.connect(check_database_schema(Entry, __name__), weak=False)
class EntryAdmin(item_editor.ItemEditor):
date_hierarchy = 'published_on'
list_display = ['__unicode__', 'published', 'published_on']
list_filter = ['published',]
search_fields = ['title', 'slug']
prepopulated_fields = {
'slug': ('title',),
}
raw_id_fields = []
|