On Jan 30, 2007, at 2:45 PM, Curtis W. Ruck wrote:
> We have a model with a DateTimeField, and two FloatField's.  These  
> three fields are unique_together in the database.
>
> Why when using get_or_create(datetimefield=someDatetimeObject,  
> floatfield1=float(-34.2412), floatfield2=float(1.2432)) does it not  
> return a record in the database that has those values, and then  
> fails with a duplicate key error on the unique key of those fields?



Float fields are difficult to represent precisely, some form of  
internal rounding may occur. If you need a precise value as a unique  
key, you could store them as strings or integers (remove the decimal  
point by multiplying by 10,000). Of course, you'll then have to  
convert values when you query the database.

Here's more on how Python handles floating point:
http://docs.python.org/tut/node16.html

Don




--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to