-
I am modeling products (plants in my case) that have a foreign key relationship to a genus model.
I have a
I added a second filter to allow filtering by Latin name:
This is used in my template like:
This approach doesn't work as:
Where am I going wrong here? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
By default, choice labels are generated using
This will still depend on your view, but I can at least say that you don't need to have two separate filterset classes.
You've provide the |
Beta Was this translation helpful? Give feedback.
-
Thanks so much. I guess I was not fully understanding how I changed my
I still don't really understand why the |
Beta Was this translation helpful? Give feedback.
By default, choice labels are generated using
__str__
. To change this, you'll need to implementlabel_from_instance
as described at the very bottom of theModelChoiceField
docs. Then, you'll need to provide thefield_class
to yourModelMultipleChoiceFilter
.This will still depend on your view, but I can at least say that you don't need to have two separate filterset classes.
genus__common
andgenus__latin
can be members of the same filterset.