On Mon, 2007-03-12 at 19:37 +0000, Stephen Mizell wrote:
> I'm trying my hardest to make an archive list on our website. I can
> pull them up fine with Model.objects.dates('pub_date','month') but I
> can't use .filter() on them for some reason. We add things to the
> database sometimes with a pub_date > today's date so things are
> automatically published in the future. Is there a way to use
> something to filter these out?
>
> Model.objects.dates('pub_date','month',
> order='DESC').filter(pub_date__month__lte=date.month,
> pub_date__year__lte=date.year)
>
> Note: To explain the "lte" on month and year, we want new articles to
> post the first day of each month. This is why I don't use now().
The .dates() methods returns a DateQuerySet, not a QuerySet. It's
intended to be the last thing in the sequence of methods that you call.
A DateQuerySet is a subset of QuerySet, but because it's had the query
slightly altered to return only the dates, it doesn't have the full
flexibility for further actions that a QuerySet does. That might well be
biting you here.
Try doing the filtering first (since filter() returns a QuerySet) and
then calling dates() on the result. So
Model.objects.filter(....).dates(....)
Remember that method calls are evaluated left to right, so you can't
just put them in any order if they return slightly different results.
Regards,
Malcolm
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---