Sunday, March 27, 2011

Re: Integrity Error on chained FKs

Daniel,

thanks for pointing that out, the amended code now does what it was
supposed to do. makes perfect sense when you explained it.
i already had the slug and user excluded, which is why it allowed me
to add them but didn't validate them im guessing.

chained fk's was down to the error message. i thought that my link
from survey to venue to userprofile to user might have been the
issue.

On Mar 27, 2:03 pm, Daniel Roseman <dan...@roseman.org.uk> wrote:
> On Sunday, March 27, 2011 9:41:53 AM UTC+1, shofty wrote:
>
> > this is the view code...
>
> >     u = get_object_or_404(UserProfile, user=request.user)
> >     if request.method == "POST":
> >         # submitted the add venue form
> >         venue_form = VenueForm(request.POST)
> >         venue_form.user = u
> >         venue_form.slug = slugify(request.POST['name'])
> >         if venue_form.is_valid():
> >             venue_form.save()
>
> The lines starting with `venue_form.user` and `venue_form.slug` aren't doing
> what you intend. They aren't setting the value of the form's fields to
> anything - they are just setting arbitrary attributes on the form, which are
> ignored.
>
> What you mean to do is this:
>
>         venue_form = VenueForm(request.POST)
>         if venue_form.is_valid():
>             venue = venue_form.save(commit=False)
>             venue.user = u
>             venue.slug = slugify(venue.name)
>             venue.save()
>
> To make this work, you'll probably need to add the user and slug fields to
> the form's `exclude` tuple.
>
> I don't know what this has to do with "chained FKs", though.
> --
> DR.

--
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 django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate