From: Radek Czajka Date: Thu, 10 Jan 2013 14:24:43 +0000 (+0100) Subject: add published entry manager X-Git-Tag: 0.3.1~2 X-Git-Url: https://git.mdrn.pl/django-migdal.git/commitdiff_plain/0f9e09dcdab10f7baf944083b9bb85a4b04d9ba0?ds=sidebyside add published entry manager --- diff --git a/migdal/models.py b/migdal/models.py index 3ab375d..86f010c 100644 --- a/migdal/models.py +++ b/migdal/models.py @@ -14,7 +14,7 @@ from django.template import loader, Context from django.utils.translation import get_language, ugettext_lazy as _, ugettext from django_comments_xtd.models import XtdComment from markupfield.fields import MarkupField -from fnpdjango.utils.models.translation import add_translatable +from fnpdjango.utils.models.translation import add_translatable, tQ from migdal import app_settings from migdal.fields import SlugNullField @@ -40,6 +40,12 @@ add_translatable(Category, { }) +class PublishedEntryManager(models.Manager): + def get_query_set(self): + return super(PublishedEntryManager, self).get_query_set().filter( + tQ(published=True) + ) + class Entry(models.Model): type = models.CharField(max_length=16, choices=((t.db, t.slug) for t in app_settings.TYPES), @@ -55,6 +61,9 @@ class Entry(models.Model): categories = models.ManyToManyField(Category, null=True, blank=True, verbose_name=_('categories')) first_published_at = models.DateTimeField(_('published at'), null=True, blank=True) + objects = models.Manager() + published_objects = PublishedEntryManager() + class Meta: verbose_name = _('entry') verbose_name_plural = _('entries')