Django Filters not adding ---- to choices?

249 views
Skip to first unread message

Subsume

unread,
Apr 28, 2011, 12:48:13 PM4/28/11
to django-filter
I'm using Django filters in a project but I'm suprised by the out-of-
the-box behavior with regard to choices.

A model with field 'state' that uses the USStateField, I create a
FilterSet on this model and specify fields ['state'] and nothing else.
What I'm left with is a form that gives me a dropdown box with no
'------' option! Inspecting with pdb, I find that the field is
required = False.

Is this expected behavior? Could such a shockingly basic bug exist in
django-filters or have I missed something?

Strangely, when I create a FilterSet and I specify the fields manually
(field = django_filters.SomeFilter(...)) the choices are as expected.

Sergiy Kuzmenko

unread,
Apr 28, 2011, 1:17:34 PM4/28/11
to django...@googlegroups.com
That's a known bug. I have submitted a pull request[1] that fixes this
problem awhile ago but it hasn't been acknowledged yet.

[1] https://github.com/alex/django-filter/pull/40

Cheers

Subsume

unread,
May 6, 2011, 6:05:09 PM5/6/11
to django-filter
Sorry, could you link me to the commit that achives it?

Sergiy Kuzmenko

unread,
May 8, 2011, 9:46:50 PM5/8/11
to django...@googlegroups.com
Maybe I read your message too quickly. I saw you were having trouble with USStateField. When I had to use django_filters for one of my project I realized that it only worked with filters defined in django.db.models [1]. Any other field inheriting would be excluded [2]. As my project had a number of non-standard fields, I put a quick patch to address that. It allows to django_filter to generate filters for any field inheriting from those defined in django.db.models (and that would include USStateField).

My branch with this fix is here: https://github.com/shelldweller/django-filter/tree/field-inheritance

If this does not address your problem I am sorry I mislead you.

Cheers
SK

[1] https://github.com/alex/django-filter/blob/master/django_filters/filterset.py#L115
[2] https://github.com/alex/django-filter/blob/master/django_filters/filterset.py#L283

Владислав Полухин

unread,
Jul 28, 2011, 2:37:30 AM7/28/11
to django...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages