I would like to get an answer for this too. Just reading through
Justin's code, I have figured out the solution to a problem I was
stuck on for a few days (I am new to Django so reading and learning
about the _set_queryset function was a godsend).

Also, I was wondering if someone can point me in the direction of any
documentation which describes other *obscure* function calls like
_set_queryset etc. I didn't see it anywhere in the main documentation
section. Had I seen it, I probably would have saved myself a few hours
of pulling my hair out.

Best,

R

On Wed, Apr 9, 2008 at 11:19 PM, Justin <[EMAIL PROTECTED]> wrote:
>
>  I noticed when looking at some code that after setting the queryset,
>  it appears in the form.  I can call ._get_queryset() or .queryset and
>  it looks updated.
>
>  The problem occurs in the actual form rendered.
>
>  form.as_ul() does not have the updated choices for the checkbox.  I'm
>  digging through django code but still nothing.
>
>
>
>  On Apr 8, 11:05 pm, Justin <[EMAIL PROTECTED]> wrote:
>  > 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to