On Mon, Feb 8, 2010 at 1:46 PM, Anders Eide <eide.and...@gmail.com> wrote:
> I have a table width movies, and I would like to make a form and a
> view thats updates a row.
>
> I build the form automatically from a model
>
> class SaveMovieForm(ModelForm):
>    class Meta:
>        model = Movie
>    id = forms.IntegerField(
>        widget = forms.HiddenInput(),
>        required = False
>    )
>
> And populates it like this
>
> movie = Movie.objects.get(id=id)
>
> form = SaveMovieForm({
>    'title' = movie.title,
>    ...
> })
>
> Then sends the form to the template using RequestContext and
> render_to_response
>
> But I'm getting the warning that the title already exists. This
> results in that I can't update the row. How can I tell the form that
> the request is a update, not a create?
>

Pass the movie as the instance argument to SaveMovieForm, eg:

form = SaveMovieForm(data=request.POST, instance=movie)

Cheers

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to