On Aug 22, 10:21 am, sean <[EMAIL PROTECTED]> wrote:
> That's the problem, I don't know how to cache the queryset.
> But for what it's worth, here's something i tried. I tried to take
> advantage of the default caching of querysets, but that doesn't work
> here.
>
> mediaform = CustomMediaForm
> # get the initial queryset fo a large table
> qs=mediaform.base_fields['somefield'].queryset
You could just evaluate this query set once and turn it into a list of
tuples:
my_choices = [(o.id, o.name) for o in qs]
Then use my_choices in all your forms in the below loop.
>
> forms = []
>
> for i in requested_forms:
> form=mediaform(data, auto_id="some_generated_id")
> # assign the queryset to the choices
> form.base_fields['somefield'].queryset = qs
That would become:
form.base_fields['somefield'].choices = my_choices
> forms.append(form)
>
> And yes, I know it's hackish and not nice at all ;-)
Another option is to define your queryset outside this view method
rather than fetching it from form.field.queryset that you do above.
That way, the same instance of the queryset gets used in all the forms
you build in that loop.
How many choices does the queryset return on average? Is it a huge
drop down list?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---