I'm wading – carefully – into some basic geolocation using HTML5. I currently have a meta form for my first Django application that has space for lat and long coordinates and have found the proper code to obtain those coordinates using the Google Maps API (pretty simple stuff).
Next step: inserting those coordinates automatically into the meta form when a user access the application. The application would ideally allow users to make posts and store their coordinates for future reference and filtering (that part is the big endeavor; one step at a time).
Using JavaScript (which I know very little) with Django in this manner seems to be the most efficient manner to accomplish this and was looking to see if there's a straightforward method for doing this. I found some ways to accomplish this that may work using jQuery, but with the meta form automatically setting up the form's structure it doesn't seem as if there's a simple way to add an "id" to the form (researched but can't seem to find a means).
Any insight or experience that can shared would be greatly appreciated.
Model:
class Story(models.Model):
objects = StoryManager()
title = models.CharField(max_length=100)
topic = models.CharField(max_length=50)
copy = models.TextField()
author = models.ForeignKey(User, related_name="stories")
zip_code = models.CharField(max_length=10)
latitude = models.FloatField(blank=False, null=False)
longitude = models.FloatField(blank=False, null=False)
date = models.DateTimeField(auto_now=True, auto_now_add=True)
pic = models.ImageField(upload_to='pictures', blank=True)
caption = models.CharField(max_length=100, blank=True)
def __unicode__(self):
return " %s" % (self.title)
Form:
class StoryForm(forms.ModelForm):
class Meta:
model = Story
exclude = ('author',)