Cache a ModelChoiceField queryset in a FormSet

52 views
Skip to first unread message

jxro...@gmail.com

unread,
Mar 28, 2018, 1:41:34 AM3/28/18
to Django users
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!

jxro...@gmail.com

unread,
Apr 6, 2018, 5:08:32 AM4/6/18
to Django users
Since nobody gave a feedback, let me provide a link to the solution I came up with, in case anybody is interested: https://stackoverflow.com/a/49689142/2775385
Reply all
Reply to author
Forward
0 new messages