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.
* Attachment "django querys.png" added.
when have fk in model generate more db querys
* status: new => closed
* type: Uncategorized => Cleanup/optimization
* resolution: => duplicate
Comment:
Duplicate of #18597.
--
Ticket URL: <https://code.djangoproject.com/ticket/33485#comment:1>