Queryset-refactor merge in newforms-admin branch broke date_hierarchy filter

6 views
Skip to first unread message

Marcob

unread,
Apr 27, 2008, 2:02:12 PM4/27/08
to Django developers
I found that after queryset-merge in newforms-admin date_hierarchy
filter doesn't work anymore: years and month are repeated.
To fix it I wrote this quick hack in django/contrib/admin/templatetags/
admin_list.py:

Line 240:
- days = cl.query_set.filter(**{year_field: year_lookup,
month_field: month_lookup}).dates(field_name, 'day')
+ days = list(set(cl.query_set.filter(**{year_field:
year_lookup, month_field: month_lookup}).dates(field_name, 'day')))

Line 252:
- months = cl.query_set.filter(**{year_field:
year_lookup}).dates(field_name, 'month')
+ months = list(set(cl.query_set.filter(**{year_field:
year_lookup}).dates(field_name, 'month')))

Line 266:
- years = cl.query_set.dates(field_name, 'year')
+ years = list(set(cl.query_set.dates(field_name, 'year')))

I don't know if this is the right way.

Ciao.
Marco.

Brian Rosner

unread,
Apr 27, 2008, 3:25:25 PM4/27/08
to django-d...@googlegroups.com

On Apr 27, 2008, at 12:02 PM, Marcob wrote:
>
> I found that after queryset-merge in newforms-admin date_hierarchy
> filter doesn't work anymore: years and month are repeated.
> To fix it I wrote this quick hack in django/contrib/admin/
> templatetags/
> admin_list.py:

Can you open a ticket in Trac with your patch attached. That will be
much easier to track than in the mailing list. Thanks.

Adrian Holovaty

unread,
Apr 27, 2008, 7:01:26 PM4/27/08
to django-d...@googlegroups.com
On Sun, Apr 27, 2008 at 1:02 PM, Marcob <marc...@gmail.com> wrote:
> I found that after queryset-merge in newforms-admin date_hierarchy
> filter doesn't work anymore: years and month are repeated.

For the record, this bug exists in trunk, also. I'm going to take a
look at it now...

Adrian

--
Adrian Holovaty
holovaty.com | everyblock.com | djangoproject.com

Adrian Holovaty

unread,
Apr 27, 2008, 8:21:36 PM4/27/08
to django-d...@googlegroups.com
On Sun, Apr 27, 2008 at 1:02 PM, Marcob <marc...@gmail.com> wrote:
> I found that after queryset-merge in newforms-admin date_hierarchy
> filter doesn't work anymore: years and month are repeated.

Thanks for reporting this, Marco. Turns out the bug was a few layers
deeper -- it was in the handling of dates(), not in the admin code.
I've fixed it in [7486] and added unit tests in [7485].

Fidel Ramos

unread,
Apr 30, 2008, 4:37:13 AM4/30/08
to Django developers
date_hierarchy is broken for me when filtering models with a nullable
date field and at least one instance is None. It raises an
AttributeError " 'NoneType' object has no attribute 'year' ". It seems
the error could be in line 265 of admin's admin_list.py.

Could someone confirm to open a ticket in the trac?
Reply all
Reply to author
Forward
0 new messages