Makes a call to Google's geocoder and returns the latitude and longitude as a string or returns an empty string. Called by the save method to save the lat and long to the db to be used when rendering maps on the frontend. Reduces the number of calls to geocoder by calling only when saving, not on every viewing of the object.
Be sure to import *urllib* and the project's *settings*, and to define GOOGLE_API_KEY in settings.py.
**Example:**
def save(self):
location = "%s+%s+%s+%s" % (self.address, self.city, self.state, self.zip_code)
self.lat_long = get_lat_long(location)
if not self.lat_long:
location = "%s+%s+%s" % (self.city, self.state, self.zip_code)
self.lat_long = get_lat_long(location)
super(Foo, self).save()
- google-maps
- geocode
- google-api
- latitude
- longitude
This module is comes from the original staticview.py from django. But when you using it, it can looks for static files in your app's subdirectory. So that you can put static files which concerned with your app in a subdirectory of the app. I should say it method only suit for developing, so if you want to deploy your application to apache, you should copy static folder to the real media folder. And if you keep the same structure of the directory, then it'll be very easy. And you can write a little script to automatically do that. But for now, I didn't have written one yet :P
How to use it in urls.py
--------------------------
Here's an example:
(r'^site_media/(.*)$', 'utils.staticview.serve', {'document_root': settings.SITE_MEDIA, 'app_media_folder':'media'}),
It seems just like the original one in django. But there is a new parameter "app_media_folder", it's used for subdirectory name of app. So your django project folder structure maybe seem like this:
/yourproject
/apps
/appone
/media
/css
/img
/js
/media
/css
/img
/js