Database Reference
In-Depth Information
'country_name'])
geoj = GeoJSON.GeoJSON()
s = geoj.encode(djf.decode(sightings))
return HttpResponse(s)
3. Add the following @property definitions to the Sighting class in the
models.py fileunder chp09/wildlife/sightings .The get_geojson
view will need to use these properties to compose the GeoJSON view
needed from the Leaflet map and the information pop up. Note how in
the country_name property, you are using GeoDjango, which contains a
spatial-lookup QuerySet operator to detect the country where the sighting
happened:
@property
def date_formatted(self):
return self.date.strftime('%m/%d/%Y')
@property
def animal_name(self):
return self.animal.name
@property
def animal_image_url(self):
return self.animal.image_url()
@property
def country_name(self):
country =
Country.objects.filter(geometry__contains=self.geometry)[0]
return country.name
4. Add a home.html file, containing the following code, under sightings/
templates/sightings .UsingtheDjangotemplatelanguage,youwilldis-
playthenumberofsightingsinthesystem,alistofthesesightingswiththe
main information for each of them, and the Leaflet map. Using the Leaflet
JavaScriptAPI,youaddabaseOpenStreetMaplayertothemap.Then,you
make an asynchronous call, using jQuery, to the get_geojson view (ac-
cessedbyadding /geojson totherequestURL),thatincaseofsuccessof
Search WWH ::




Custom Search