Python Forum
How to fetch latitude,longitude from location and save them separately in db(Django2) - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html)
+--- Thread: How to fetch latitude,longitude from location and save them separately in db(Django2) (/thread-11071.html)



How to fetch latitude,longitude from location and save them separately in db(Django2) - PrateekG - Jun-21-2018

Hi All,


I have created a model in Django 2.0.6+Python 3.6 which maps to a table in Database i.e. store table
This store table has columns- id, name, address, location, latitude, longitude.

Currently user don't have to manually fill the location field, it is filled with latitude,longitude based on the address entered. For this purpose I am using following package in Django-location field example

I need to fetch the values of latitude/longitude from this location field and save into respective latitude and longitude columns in db.

How can I achieve this?

My current code-
models.py:
from location_field.models.plain import PlainLocationField
class Store(OwnedModel):
    name = models.CharField(max_length=100)
    address = models.TextField(default='Mumbai')
    location = PlainLocationField(based_fields=['address'], zoom=7, null=True)

    class Meta:
        managed = False
        db_table = 'store'
admin.py:
class StoreAdmin(admin.ModelAdmin):
    list_display = ('id', 'name', 'address')