I specialize django.contrib.gis.geos.Point just to better create and handle points with latitude and longitude latitude.
My current code is:
from django.contrib.gis.geos import Point class LLPoint(Point): def __init__(self, *args, **kwargs): lat = kwargs.get('latitude') lng = kwargs.get('longitude') if lat and lng: super(LLPoint, self).__init__(lng, lat) elif lat or lng: raise TypeError(u'You must both declare latitude and longitude, ' 'not just one of them.') else: super(LLPoint, self).__init__(*args, **kwargs) def __unicode__(self): c = self.coordinates() return u'LLPoint Lat: %.5f Lng: %.5f' % (c['latitude'], c['longitude']) def coordinates(self): return { 'latitude': self.coords[1], 'longitude': self.coords[0] }
The problem is this:
>>> LLPoint(latitude=10.0, longitude=20.0) <Point object at 0xdeadbeef>
Why does it return a Point object? Thus, I cannot use anything that I declared in a subclass. If I try to reproduce the problem using stub classes, this will work. This is probably very stupid, but I do not see.
source share