CheckboxSelectMultiple widget setted up trough Meta class triggers a LOT of queries
See original GitHub issueI’m on django 1.6 and testing with the lates dev branc of crispy forms (f75f4de128af36e174e4be9a7c201a9828dbf7aa) , and I have 2 models linked by a m2m relation, say Blogpost
and Tags,
I also have a BlogpostForm
(modelform) that specifies tags as a field to display:
If I specify CheckboxSelectMultiple
as a widget for the tags
field in the Meta
class for BlogpostForm
, and render that form trough crispy forms I end up with something like 120 queries for 20 tags, normal django form rendering does not have this problem (something like 6 queries in total).
A workaround is to specify the widget not in the Meta class of BlogpostForm (widgets = {'tags' : CheckboxSelectMultiple,}
) but in its __init__
method (self.fields['tags'].widget = CheckboxSelectMultiple()
).
Is that a plausible crispy-forms issue or I misunderstand how something related to that widget initialization works?
Issue Analytics
- State:
- Created 10 years ago
- Comments:6 (1 by maintainers)
Top GitHub Comments
I had the same problem, But I found a simple solution that needs to be tested. Just add
cache_choices=True
to yoursModelMultipleChoiceField
attrs. Be carefull, it is undocumented django ability that was introduced as a solution for this ticket https://code.djangoproject.com/ticket/3534This is a Django issue. It pops up everywhere we have a
choices
field.I guess the solution is to make choices a callable and implement caching there.
If it’s an issue it’s a Django issue. I’m going to close this here.