django-filter
django-filter copied to clipboard
Is it possible to control the `str` display of ModelMultipleChoiceFilter results?
When using ModelMultipleChoiceFilter, the returned display value of each object in the returned queryset is the str() method of the model being queried. In most cases you can control this by altering the str() method of the queried model, but in our case we don't want to - we want to control it at the ModelMultipleChoiceFilter level.
Is this currently possible? If not, this is a feature request :)
Filters use Django form fields under the hood, so this should be more a general question of "how do I modify the choice labels for a ModelMultipleChoiceField?"
You should be able to do this by implementing YourModel.label_from_instance.
Aha! Excellent information, thanks. This might be a useful mention in the docs (though I understand it doesn't make sense to mention it in many places). Thanks!
Yeah - one thing I'd like to clarify the docs is the relationship between filterset/form and filter/field.