Can't filter by a related object's field called 'year', 'month' or 'day'
|Reported by:||Alex Ogier||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 )
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
|Severity:||Normal → Release blocker|
|Triage Stage:||Unreviewed → Accepted|
comment:4 Changed 5 years ago by
|Component:||contrib.admin → Database layer (models, ORM)|
|Severity:||Release blocker → Normal|
|Summary:||Can't list_filter across a relationship on a SmallIntegerField → Can't filter by a related object's field called 'year', 'month' or 'day'|