Wednesday, October 26, 2016

Re: Silently continuing past an exception: is this proper? how else can I do this?

On Sun, Oct 23, 2016 at 1:39 PM, Andrew Chiw
<randomshinichi4869@gmail.com> wrote:
> It seems there's a problem with my code, because you're just supposed to
> pass a dict to DocumentForm (or any modelForm really), not a model instance.
>
> I actually want to make a DocumentForm initialized with values from an
> existing Document, so I can list existing Documents and provide a way to
> re-upload them and edit their description. Is this the right way to do it?

DocumentForm(instance=d)

I can't see anywhere in the docs where this is explicitly specified as
the stock ModelForm API, but it is firmly implied by this page:

https://docs.djangoproject.com/en/1.10/topics/forms/modelforms/#modelform

The first positional argument is expected to be data submitted by the browser.

Cheers

Tom

--
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAFHbX1JQiqaEbKrkzhRN2u8NU5tFO5jWQZgaqDWcLAXAKcKaDg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment