Trying to wrap my head around django forms and django's way of doing things. I want to create a basic web form that allows a user to enter an address and have that address geocoded and stored in the database.
I created a location model:
class Location(models.Model): address = models.CharField(max_length=200) city = models.CharField(max_length=100) state = models.CharField(max_length=100, null=True) postal_code = models.CharField(max_length=100, null=True) country = models.CharField(max_length=100) latitude = models.DecimalField(max_digits=18, decimal_places=10, null=True) longitude = models.DecimalField(max_digits=18, decimal_places=10, null=True)
And defined the form:
class LocationForm(forms.ModelForm): class Meta: model = models.Location exclude = ('latitude','longitude')
In my opinion, I use form.save() to save the form. This works and stores the address in the database.
I created a module for geocoding an address. I'm not sure what the way to do something is django, but, in my opinion, before I save the form, I need to geocode the address and set lat and long. How to set latitude and longitude before saving?
python django django-forms geocoding
User
source share