Perfect, thanks
On Sun, 1 Sep 2013 18:44:07 +0200
Thomas Orozco <thomas@orozco.fr> wrote:
> The URL parameter (iid) is accessible in your view in self.kwargs["iid"].
>
> You can pass it to the form by overriding your view's `get_initial`
> method
> ( https://github.com/django/django/blob/1.6b2/django/views/generic/edit.py#L22
> )
>
>
> `get_initial` should return a dict, and you should use:
>
> {
> 'name_of_the_model_field': self.kwargs["iid"]
> }
>
>
> On Sun, Sep 1, 2013 at 6:37 PM, Drew Ferguson
> <drew@afccommercial.co.uk>wrote:
>
> > Hi
> >
> > I have gotten myself badly confused today trying to figure this out.
> >
> > If I have these elements
> >
> > # urls.py
> > url(r'^banker/(?P<iid>\d+)/iac$', view = IacCreateView.as_view())
> >
> > # views.py
> > class IacCreateView(LoginRequiredMixin, CreateView):
> > template_name = 'iaccount_form.html'
> > model = Iaccount
> > form_class = IaccountForm
> >
> > # forms.py
> > class IaccountForm(forms.ModelForm):
> > class Meta(object):
> > model = Iaccount
> >
> > How can I use a value (iid) from the url to set a field's initial
> > value in the form
> >
> > or more generally pass initial values into the form from a previous
> > page --
> > Drew
> >
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Django users" group.
> > To unsubscribe from this group and stop receiving emails from it, send
> > an email to django-users+unsubscribe@googlegroups.com.
> > To post to this group, send email to django-users@googlegroups.com.
> > Visit this group at http://groups.google.com/group/django-users.
> > For more options, visit https://groups.google.com/groups/opt_out.
> >
>
--
Drew Ferguson
AFC Commercial
http://www.afccommercial.co.uk
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment