Fixed #20849 -- ModelForms do not work well with prefetch_related. #1840

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
3 participants

dgym commented Nov 1, 2013

model_to_dict() (used when rendering forms) queries the database
to get the list of primary keys for ManyToMany fields. This is
unnecessary if the field queryset has been prefetched, all the
keys are already in memory and can be obtained with a simple
iteration.

This commit can save many database queries when using a formset of ModelForms containing ManyToMany fields.

@jimpot @dgym jimpot Fixed #20849 -- ModelForms do not work well with prefetch_related.
model_to_dict() (used when rendering forms) queries the database
to get the list of primary keys for ManyToMany fields. This is
unnecessary if the field queryset has been prefetched, all the
keys are already in memory and can be obtained with a simple
iteration.
c3e7a28
Member

akaariai commented Nov 3, 2013

Merged manually

akaariai closed this Nov 3, 2013

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