def save(self, *args, **kwargs): super(City,self).save() if self.state is None and self.zip.count() > 0: address = build_address(str(self.name), str(self.zip.all()[0].code)) location = geocode(address) state, created = State.objects.get_or_create(name=location['state'], short=location['state_short']) self.state = state super(City,self).save(*args, **kwargs)
def save(self, *args, **kwargs): address = build_address(self.address, self.zip.code) location = geocode(address) if location: self.lat = location['lat'] self.lng = location['lng'] self.point = Point(float(self.lng), float(self.lat)) super(Retailer,self).save(*args, **kwargs)