Python Forum
Why some Django fields are not saved in database?
Thread Rating:
  • 3 Vote(s) - 3.67 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why some Django fields are not saved in database?
#1
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Django: View is unable to find attributes of database model pythonpaul32 0 484 Dec-07-2023, 06:38 PM
Last Post: pythonpaul32
  Selenium fields containing a word graham23s 3 2,781 Aug-22-2023, 12:35 PM
Last Post: Gaurav_Kumar
  Registration Form Fields rwahdan 2 1,837 Aug-09-2022, 10:35 AM
Last Post: Addweb
  Save JSON data to sqlite database on Django Quin 0 2,804 Mar-26-2022, 06:22 PM
Last Post: Quin
  Error - ManyToMany Fields in Django rob25111 0 1,504 Jan-17-2021, 04:58 PM
Last Post: rob25111
  Send email to gmail after user fill up contact form and getting django database updat Man_from_India 0 2,071 Jan-22-2020, 03:59 PM
Last Post: Man_from_India
  how retrieve database save multiple data in web Django 2.1 taomihiranga 0 2,764 Jul-30-2019, 04:58 PM
Last Post: taomihiranga
  Django: How to automatically substitute a variable in the admin page at Django 1.11? m0ntecr1st0 3 3,247 Jun-30-2019, 12:21 AM
Last Post: scidam
  Django- Remove leading zeros in values from database ntuttle 1 3,463 Mar-07-2019, 07:30 PM
Last Post: nilamo
  Django- which database i should use? with best speed and performance!! ma_norouzifar 4 4,777 Dec-10-2018, 09:47 AM
Last Post: ma_norouzifar

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020