On 7 Sie, 17:40, Doug B <[EMAIL PROTECTED]> wrote:
> form = NewsForm(request.POST, somegroup=somegroup)
>
> given your form __init__ definition, you are passing POST into the
> spot for somegroup.
>
> What I did to get around this was something like this:
>
> class NewsBaseForm(BaseForm):
>     def __init__(self, *args, **kwargs):
>         nkwargs = kwargs.copy()
>         if nkwargs.has_key('somegroup'):
>                somegroup=kwargs.pop('somegroup')
>         else:
>                somegroup=None
>         super(NewsBaseForm, self).__init__(*args, **nkwargs)
>         self.fields['place'].choices = [(p.id, p.name) for p in
> Place.objects.filter(display_for__pk=somegroup)]
>
> There may be easier ways

Hello,

I was wondering if I can do this in form definition ..

Now I have to "send" the variable twice, when sending the POST dict.
to the form,
and when initiating it.

NewForm = forms.form_for_model(Model, form=SomeBaseForm)

if request.method == "POST":
    form = NewForm(request.POST, somegroup=somegroup)
    do_some_stuff()

else:
    form = Newform(somegroup=somegroup)

return render_to_response("x/y.html", {'form' : form })

Regards,

--
Robert



--~--~---------~--~----~------------~-------~--~----~
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