Opened 4 years ago
Closed 4 years ago
#32912 closed Bug (duplicate)
Using label_from_instance on ModelChoiceField requires resetting queryset first
| Reported by: | mbehm | Owned by: | nobody |
|---|---|---|---|
| Component: | Forms | Version: | 3.2 |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
The part in the following old issue about having to reset queryset for the label_from_instance to work is valid, even if you follow the documentation to the letter your custom version of label_from_instance won't be called unless you also define the queryset, even if the queryset would be the default.
Note:
See TracTickets
for help on using tickets.
I'm sorry but I don't see anything new in your description. As far as I'm aware you don't need do "reset" a queryset when subclassing
ModelChoiceFieldas documented, e.g.from django.forms import ModelChoiceField class MyModelChoiceField(ModelChoiceField): def label_from_instance(self, obj): return "My Object #%i" % obj.id class Aform(forms.Form): user = MyModelChoiceField(queryset=User.objects.all())Duplicate of #6839.