On Wed, Dec 10, 2008 at 10:26 AM, Berco Beute <[EMAIL PROTECTED]> wrote:

>
> Here's the code:
>
> http://dpaste.com/97758/
>
> My modelform stays invalid although the required fields of the
> instance are set. The 'product' field is excluded from the form
> because it shouldn't be edited. When the form is posted I'm trying to
> set the product on the form instance again, but that somehow doesn't
> work out to well.
>
> In line 17 the form is found to be invalid although I set the
> OrderLineForm's OrderLine instance has the required 'product' field
> set with the appropriate object (tested at line 16). I thought
>
> I've successfully used this strategy in other projects but I'm at a
> loss what happens here. I'm also not sure how to debug this properly.
>
> Any pointers/suggestions would be highly appreciated.
>

You say you excluded 'product' from the form but the code you posted has not
excluded 'product', it has excluded 'parent' and 'usePrice'.

Also, the technique you are using of creating the ModelForm with an instance
parameter so as to provide values for fields that are excluded from the form
(as described here:
http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#using-a-subset-of-fields-on-the-form)
is to avoid errors during model save, not form validation.  This data is not
used during form validation (after all it's for supplying values for the
model instance for fields excluded from the form -- so the form knows
nothing of these fields and won't attempt to validate them.  You seem to be
confusing two separate things here -- what's a required field on the form
and what's required when saving an instance to the DB.

So you have not excluded 'product' from the form, and the form field is
required, so when you get a POSTed form that has an empty value for
'product', the form fails to validate.  The fix may be as simple as really
excluding 'product' from the from, though I'm not sure why you didn't see
that 'product' was not actually excluded from the form when looking at
it....

Karen

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
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