def save(self, *args, **kwargs): address = self.code location = geocode(address) self.lat = location['lat'] self.lng = location['lng'] self.point = Point(float(self.lng), float(self.lat)) super(Zip, self).save(*args, **kwargs)
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)
def clean_zip(self): try: zip = Zip.objects.get(code=self.cleaned_data["zip"]) except Zip.DoesNotExist: zip = Zip(code=self.cleaned_data["zip"]) location = geocode(self.cleaned_data["zip"]) zip.lng = location["lng"] zip.lat = location["lat"] zip.save() return zip
def clean_zip(self): try: zip = Zip.objects.get(code=self.cleaned_data['zip']) except Zip.DoesNotExist: zip = Zip() location = geocode(self.cleaned_data['zip']) zip.lng = location['lng'] zip.lat = location['lat'] zip.code = self.cleaned_data['zip'] zip.save() return zip
def search(request, template_name='retailer/search.html'): form = SearchForm() retailers = list() if request.method == 'POST': form = SearchForm(request.POST) if form.is_valid(): location = geocode(form.cleaned_data['address']) lat = location['lat'] lng = location['lng'] pnt = Point(float(lng), float(lat)) retailers = Retailer.objects.filter(point__distance_lte=(pnt, D(mi=5))) #retailers = Retailer.objects.filter(zip__code=48104) else: form = SearchForm() variables = RequestContext(request, { 'form':form, 'retailers':retailers, }) return render_to_response(template_name, variables)