Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Coordinates(object):
- def __init__(self, lng, lat):
- super(Coordinates, self).__init__()
- self.lng = float(lng)
- self.lat = float(lat)
- def to_sql(self):
- return "GeomFromText('POINT(%s %s)')" % (self.lng, self.lat)
- def __unicode__(self):
- return 'Coordinates(lat=%s, lng=%s)' % (self.lat, self.lng)
- @staticmethod
- def to_python(value):
- return value
- # write the rest when i know what to do
- return Coordinates(0, 0)
- class GeometryField(models.Field):
- __metaclass__ = models.SubfieldBase
- def __init__(self, *args, **kwargs):
- #self.max_length = 68
- super(GeometryField, self).__init__(*args, **kwargs)
- self.spatial = True
- def db_type(self, connection):
- return 'GEOMETRY'
- def to_python(self, value):
- if isinstance(value, Coordinates):
- return value
- return Coordinates.to_python(value)
- def get_prep_value(self, value):
- return self.to_python(value)
- def get_db_prep_save(self, value, connection):
- return self.to_python(value).to_sql()
- def value_to_string(self, obj):
- value = self._get_val_from_obj(obj)
- return self.get_db_prep_value(value)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement