On Jun 15, 4:23 pm, Genis Pujol Hamelink <[email protected]> wrote: > yes, but what if it's a new object and not an existing one? How do I test > this? The request method will be POST, so form will be form = > MyForm(request.POST)... so if form.pk exists in the db how do I tell it's > editing an existing object? > > if request.method == 'POST': > form = myform(request.POST) > try: > instance = myobj.objects.get(id=form.id) > form = myform(request.POST, instance=instance) > if form.is_valid(): > form.save() > else: > whatever goes here > except: > form = myform(request.POST) > if form.is_valid(): > form.save() > else: > whatever goes here > > Something like this or do u know a better way? >
I don't really understand how a newly-entered item can exist in the database already. At the very least, saving the new item would give it a new PK, so it wouldn't be a duplicate, surely. -- DR. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---

