On Jul 21, 2009, at 12:00 PM, mettwoch wrote:

>
> Hi,
>
> I'd like to implement a simple "create" & "update" form for my
> "Partner" model using ModelForm. How can I make the difference in a
> view "save" function whether the POST comes from a "creation" or an
> "update" form? Unfortunately the primary-key seems never to be
> included by default in the form fields! This would have made it easy.
>
> Got 3 view functions:
> new(request):
>   <return empty unbound form>
>
> edit(request, partner):
>   <return bound form from partner instance>
>
> save(request):
>   <if id:        # But there's no id
>         update partner
>    else:
>        create partner
>
> Many thanks for any hint
> Marc
>
> >

You don't need the save version. Your edit form will save the object  
instance whether it's new or not, with the .save() method. This is one  
of the nice things about Django models -- it simplifies things. If you  
need to do something differently depending on whether the object is  
being saved for the first time, you do it by overriding the save()  
method in the model itself.

Shawn

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