How do I do this Database Model in Django?
- by alex
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?