[Django] #32912: Using label_from_instance on ModelChoiceField requires resetting queryset first

18 views
Skip to first unread message

Django

unread,
Jul 8, 2021, 9:45:57 AM7/8/21
to django-...@googlegroups.com
#32912: Using label_from_instance on ModelChoiceField requires resetting queryset
first
--------------------------------------+------------------------
Reporter: mbehm | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: 3.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
--------------------------------------+------------------------
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.

https://code.djangoproject.com/ticket/6839

--
Ticket URL: <https://code.djangoproject.com/ticket/32912>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jul 8, 2021, 12:46:43 PM7/8/21
to django-...@googlegroups.com
#32912: Using label_from_instance on ModelChoiceField requires resetting queryset
first
------------------------+--------------------------------------
Reporter: mbehm | Owner: nobody
Type: Bug | Status: closed
Component: Forms | Version: 3.2
Severity: Normal | Resolution: duplicate

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------+--------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed
* resolution: => duplicate


Comment:

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
`ModelChoiceField` as 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.

--
Ticket URL: <https://code.djangoproject.com/ticket/32912#comment:1>

Reply all
Reply to author
Forward
0 new messages