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.

models.py:
from location_field.models.plain import PlainLocationField
class Store(OwnedModel):
  address = models.TextField(default='Mumbai')
  location = PlainLocationField(based_fields=['address'], zoom=7, null=True)

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

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

  class Meta:
      managed = False
      db_table = 'store'
admin.py:
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.