Tuesday, March 27, 2018

Cache a ModelChoiceField queryset in a FormSet

Hi,

I am using a ModelChoiceField in a simple FormSet (not a ModelFormSet). When rendering the FormSet, Django duplicates the ModelChoiceField queryset for each row of the FormSet and repeats the same query multiple times to fill the select boxes. Is there a standard solution to cache the ModelChoiceField queryset after the first query and re-use it for the rows 2 to N ?

I have found these solutions or this one, but they look like ugly hacks to me.

Any help appreciated!

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/2cb28dd1-c8da-42e7-999f-9e8e6d6d2130%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment