From 0f9e09dcdab10f7baf944083b9bb85a4b04d9ba0 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Thu, 10 Jan 2013 15:24:43 +0100 Subject: [PATCH 1/1] add published entry manager --- migdal/models.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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') -- 2.20.1