Can't filter by a related object's field called 'year', 'month' or 'day'
|Reported by:||Clueless||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||1.3|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Description (last modified by julien)
UPDATE: The problem was originally reported in the admin but it appears it is rather an issue with the ORM -- see discussion below.
If you have a SmallIntegerField on a model that is related via a foreign key then you can't use that field as an option in list_filter. Doing so gives you the correct distinct options in the list page sidebar, but if you try to select any of them you receive a 302 redirect to /?e=1, as if you had used an unexpected query-string parameter.
Here's a small example to try yourself:
# models.py from django.db import models class Rel(models.Model): year = models.SmallIntegerField(default=2010) class Src(models.Model): rel = models.ForeignKey(Rel) # admin.py from models import Rel, Src from django.contrib import admin class RelAdmin(admin.ModelAdmin): model = Rel list_filter = ('year',) admin.site.register(Rel, RelAdmin) class SrcAdmin(admin.ModelAdmin): model = Src list_filter = ('rel__year',) admin.site.register(Src, SrcAdmin)
I'm running Django 1.3, MySQL 5.5, on Arch Linux.
Change History (5)
comment:1 follow-up: ↓ 2 Changed 5 years ago by julien
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Severity changed from Normal to Release blocker
- Triage Stage changed from Unreviewed to Accepted
comment:4 Changed 5 years ago by julien
- Component changed from contrib.admin to Database layer (models, ORM)
- Description modified (diff)
- Severity changed from Release blocker to Normal
- Summary changed from Can't list_filter across a relationship on a SmallIntegerField to Can't filter by a related object's field called 'year', 'month' or 'day'