Opened 11 years ago

Closed 11 years ago

#7147 closed (duplicate)

archive_index and archive_year create a query with "date_field IS NULL"

Reported by: Guillaume Lederrey <guillaume.lederrey@…> Owned by: nobody
Component: Generic views Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


While using django.views.generic.date_based.archive_index or archive_year, the following SQL query is generated at :

SELECT DISTINCT CAST(DATE_FORMAT(`news_news`.`publication_date`, '%Y-01-01 00:00:00') AS DATETIME)
FROM `news_news`
WHERE `news_news`.`publication_date` IS NULL ORDER BY 1 ASC

As this query returns an empty set, the "latest" variable is never loaded from DB at

I cant understand why the "publication_date IS NULL". In my understanding, if anything it should be "IS NOT NULL".

I dont know the Query system well, but it seems that archive_index and archive_year use a DateQuery. archive_month doesnt have this problem. So the problem might be related more to DateQuery than to gneric views ...

I have the following

            'queryset' : News.objects.all(),
            'date_field' : 'publication_date',
            'allow_future' : True,
            'queryset' : News.objects.all(),
            'date_field' : 'publication_date',
            'allow_future' : True,
            'make_object_list' : True,

and the following

class News(models.Model):
    """ News model """
    title = models.CharField(max_length=100, unique=True)
    slug = models.SlugField(prepopulate_from=("title",),
    author = models.ForeignKey(User)
    creation_date  = models.DateField(auto_now_add=True)
    modification_date = models.DateField(auto_now=True)
    publication_date = models.DateField(blank=True, null=True)
    ask_promotion = models.BooleanField(default=False,
                                        help_text=_("Ask for this news to be promoted on the front page. For example, an artist might be able to write news for its next gig, and have the news appear on the artist's page, but not on the front page. The artist can ask a moderator to promote the news on the front page by checking this field."))
    promoted = models.BooleanField(default=False,
                                   help_text=_("If this field is checked, the news will appear on the front page."))
    trock_news = models.BooleanField(default=False,
                                     help_text=_("Check this field if you want this news to be published in the next TrocK news."))
    text = models.TextField(blank=True)

    class Meta:
        Defines meta data on the model.
        verbose_name_plural = _('news')
        ordering = ['-publication_date', 'title',]
        permissions = (
            ("export_trock_news", _("Can export the list of news selected for the next TrocK news")),

    class Admin:
        This model is available in the admin interface.
        list_display = ('title', 'publication_date',)

    def __unicode__(self):
        return '%s' % self.title

    def get_absolute_url(self):
        The URL to this news in the date based view.
        return ('news_detail', (), {
            'year' : self.publication_date.year,
            'month' : self.publication_date.month,
            'day' :,
            'slug' : self.slug,

    def get_absolute_url_by_id(self):
        The URL to this news in the ID based view.
        return ('news_detail_by_id', (), {
            'object_id' :,

Change History (3)

comment:1 Changed 11 years ago by Guillaume Lederrey <guillaume.lederrey@…>

comment:2 Changed 11 years ago by Gilles Fabio

Same problem. It's due to the recent queryset-refactor branch merge. Try with revision 7476, that will work. And try now with revision 7477.. Boom. Broken.

This evening, I will try to detect and correct this annoying bug.

comment:3 Changed 11 years ago by oyvind

Resolution: duplicate
Status: newclosed

in favour of #7155

Note: See TracTickets for help on using tickets.
Back to Top