Python Forum

Full Version: Why some Django fields are not saved in database?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi All,

I have a store address form in Django which have fields like- name, address, location, latitude, longitude etc.
I am autofilling the latitude, longitude fields based on address with the help of django package-
django location example

In django view after the form submisson, I am able to see both fields values but in Database they are blank.
from location_field.models.plain import PlainLocationField
class Store(OwnedModel):
  address = models.TextField(default='Mumbai')
  location = PlainLocationField(based_fields=['address'], zoom=7, null=True)

  def latitude(self):
      if not self.location:
      latitude, _ = self.location.split(',')
      return latitude

  def longitude(self):
      if not self.location:
      _, longitude = self.location.split(',')
      return longitude

  class Meta:
      managed = False
      db_table = 'store'
class StoreAdmin(admin.ModelAdmin):
  list_display = ( 'address', 'latitude','longitude')
  readonly_fields = ('latitude', 'longitude',)
What Should I do to save both fields in database also?
I am using Django2.0.6, Python3.6, Mysql.