Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to control the str display of ModelMultipleChoiceFilter results? #1119

Open
shacker opened this issue Sep 6, 2019 · 3 comments

Comments

@shacker
Copy link

shacker commented Sep 6, 2019

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 :)

@rpkilby
Copy link
Collaborator

rpkilby commented Sep 6, 2019

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.

@shacker
Copy link
Author

shacker commented Sep 6, 2019

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!

@rpkilby
Copy link
Collaborator

rpkilby commented Sep 6, 2019

Yeah - one thing I'd like to clarify the docs is the relationship between filterset/form and filter/field.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants