#33485: inlineformset_factory generate more db subquerys when the model have fk
-----------------------------------------+------------------------
Reporter: DARKDEYMON | Owner: nobody
Type: Uncategorized | Status: new
Component: Forms | Version: 4.0
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 |
-----------------------------------------+------------------------
in line 859 from django.forms.models the variable qs makes a new query
from model._default_manager.get_queryset() insted of take values generated
by queryset (in my case my queryset habe select_related and
prefetch_related data because I don't want to repeat the subqueries
internally) in inlineformset_factory.
Reason why having fk in the model generates many subqueries to collect
again the data that already exists in the queryset variable, I have not
found a better way to avoid such subqueries, so this seems to me to be an
error
{{{
if isinstance(pk, (ForeignKey, OneToOneField)):
qs = pk.remote_field.model._default_manager.get_queryset()
else:
qs = self.model._default_manager.get_queryset()
qs = qs.using(form.instance._state.db)
if form._meta.widgets:
widget = form._meta.widgets.get(self._pk_field.name,
HiddenInput)
else:
widget = HiddenInput
form.fields[self._pk_field.name] = ModelChoiceField(qs,
initial=pk_value, required=False, widget=widget)
super().add_fields(form, index)
{{{
--
Ticket URL: <https://code.djangoproject.com/ticket/33485>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/053.a60dc3c6878629b4e13ef404d4c01574%40djangoproject.com.