On Fri, Apr 13, 2012 at 1:08 PM, Massimo Barbierato
<ilgeniodelbas...@gmail.com> wrote:
> Hi all, i'm new. I searched  in the group for answers to my problem, but i
> didn't find anything :(
>
> My problem is this:
>
> i have a model with two fields in unique_together, the related ModelForm and
> the view.
> When i pass an instance of my model to the form to update it and then save
> it, i receive an error that says me that there is already a row with the
> specified fields.
> I can't understand why.
>
> Here you can read my code: http://pastebin.com/vDiHvpiV
>
> Thanks a lot.

(I'm speculating a little)

In your code snippet, lines 36-38:

    sale = None
    if 'edit' in request.GET:
        sale = Sales.objects.get(sale_id=request.GET['edit'])

When you submit the form again, 'edit' is not in request.GET, so
'sale' never gets a value. When you then subsequently save the form,
it tries to save a new instance, which fails because it already
matches a row in the database.

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-users@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