How do I do this Database Model in Django?
Posted
by alex
on Stack Overflow
See other posts from Stack Overflow
or by alex
Published on 2010-03-31T00:28:01Z
Indexed on
2010/03/31
0:33 UTC
Read the original article
Hit count: 370
Django currently does not support the "Point" datatype in MySQL. That's why I created my own.
class PointField(models.Field):
def db_type(self):
return 'Point'
class Tag(models.Model):
user = models.ForeignKey(User)
utm = PointField()
As you can see, this works, and syncdb
creates the model fine.
However, my current code calculates a length between two Points using raw SQL.
cursor.execute("SELECT user_id FROM life_tag WHERE\
(GLength(LineStringFromWKB(LineString(asbinary(utm), asbinary(PointFromWKB(point(%s, %s)))))) < 55)...
This says: Select where the length between the given point and the table point is less than 55.
How can I do this with Django instead of RAW SQL? I don't want to do cursors and SELECT statements anymore. How can I modify the models.py in order to do this?
© Stack Overflow or respective owner