Re: Trying to avoid duplicate form posts/database inserts

2008-10-30 Thread Stan Dyck

Thomas Guettler wrote:
> Stan Dyck schrieb:
>   
>> I'm converting a simple database-backed web form to Django. Each form 
>> submit inserts a row into a database.
>>
>>   
>> 
>
> Hi,
>
> you can use yourmodel.objects.get_or_create(...)
> To force the uniqueness on database level you should use unique_together.
>
>   
Perfect! This appears to be what I'm looking for. Thanks.

>> To avoid multiple posts inserting duplicate rows I calculate a checksum 
>> on selected fields in the form and insert the checksum value into the 
>> database along with the form data itself. The checksum field is set in 
>> the database schema to be unique so that if an attempt is made to insert 
>> a duplicate row, the database will reject the insert.
>>   
>> 
> I think that this is not a good solution. Most databases can check
> uniqueness
> over several columns.

> My first impulse is that I could override the save method on the form 
> and use it to check the database for a checksum value. If I don't find 
> it, I insert the row along with the checksum. If I find it, I just 
> reject the insert and send the appropriate message to the response.
>   
> This might be possible, but I would handle this outside the save method.
>
>
>   Thomas
>
>
>   


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Trying to avoid duplicate form posts/database inserts

2008-10-30 Thread Thomas Guettler

Stan Dyck schrieb:
> I'm converting a simple database-backed web form to Django. Each form 
> submit inserts a row into a database.
>
>   

Hi,

you can use yourmodel.objects.get_or_create(...)
To force the uniqueness on database level you should use unique_together.

> To avoid multiple posts inserting duplicate rows I calculate a checksum 
> on selected fields in the form and insert the checksum value into the 
> database along with the form data itself. The checksum field is set in 
> the database schema to be unique so that if an attempt is made to insert 
> a duplicate row, the database will reject the insert.
>   
I think that this is not a good solution. Most databases can check
uniqueness
over several columns.

> My first impulse is that I could override the save method on the form 
> and use it to check the database for a checksum value. If I don't find 
> it, I insert the row along with the checksum. If I find it, I just 
> reject the insert and send the appropriate message to the response.
This might be possible, but I would handle this outside the save method.


  Thomas


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Trying to avoid duplicate form posts/database inserts

2008-10-29 Thread Stan Dyck

I'm converting a simple database-backed web form to Django. Each form 
submit inserts a row into a database.

To avoid multiple posts inserting duplicate rows I calculate a checksum 
on selected fields in the form and insert the checksum value into the 
database along with the form data itself. The checksum field is set in 
the database schema to be unique so that if an attempt is made to insert 
a duplicate row, the database will reject the insert.

My question is how would I duplicate this in Django? I'm still a bit new 
to this framework so I thought I'd fish this list to see if I'm missing 
an easy solution.

My first impulse is that I could override the save method on the form 
and use it to check the database for a checksum value. If I don't find 
it, I insert the row along with the checksum. If I find it, I just 
reject the insert and send the appropriate message to the response. This 
seems a little excessive though because I'd like to be able to take 
advantage of the database's ability to have unique values in specified 
fields.

Does anyone have any other suggestions?

Stan Dyck

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---