I have a form:
class TestForm(forms.Form):
name = forms.CharField(max_length=128, label="Test name")
tasks = forms.ModelMultipleChoiceField(required=False,
label="Tasks", widget=forms.CheckboxSelectMultiple,
queryset=Task.objects.none())
The goal is to have checkboxes for a set of models.... easy enough. I
initialize it to none because my goal is to update the queryset from
within the views based on specific conditions.
Inside my views.py, I have this:
>>After clicking link to create project
tasks = Task.objects.filter(project=project)
form = TestForm()
form.base_fields['tasks']._set_queryset( tasks )
data = { "form": form, "project":project }
return render_to_response("projects/create.html", data)
When I click a link to this page from another, the checkboxes are not
there because the tasks queryset is still set to Task.objects.none().
If I hit F5 to reload, the correct tasks based on the project show
up. I can hit F5 infinitely and it's correct. It's only on that
first load.
More weird... I click back out to a different project page. When I
click the link, I expect it to show the form with a new set of tasks
based on the second project as choices. Instead of the correct
choices or even none, it shows the choices from the first project.
When I hit F5, it shows the correct choices.
It's almost like it's caching the previous state between forwards.
I also tried overriding __init__ in the form. It followed the exact
same behavior. I'm using the most recent development version of the
source.
This ticket: http://code.djangoproject.com/ticket/4787 looks related
but it seems to have been resolved.
Can I update the queryset like this?
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---