Python Forum
How to auto fill latitude and longitude fields in Django2.0.6?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to auto fill latitude and longitude fields in Django2.0.6?
#5
(Jun-20-2018, 10:08 AM)gontajones Wrote: With "null=True" you allow empty values.
So, test its content before the split:
from location_field.models.plain import PlainLocationField
class Store(OwnedModel):
    building = models.ForeignKey(Building, related_name='building', on_delete=models.SET_NULL, blank=True, null=True)
    postal_code = models.CharField(max_length=6)
    address = models.TextField(default='Singapore')
    location = PlainLocationField(based_fields=['address'], zoom=7, null=True)

    @property
    def get_lat_log(self):
        latitude = ''
        longitude = ''
        try:
            print('Location: ' + str(self.location)) # DEBUG
            latitude, longitude = self.location.split(',')
        except Exception as e:
            print('Exception: ' + str(e))
        return latitude,longitude

    def __str__(self):
		return self.location

Thanks! I have put try-except in my code and able to see following print messages in logs-
Location: 8 SHENTON WAY #43-01 AXA TOWER Singapore
Exception: not enough values to unpack (expected 2, got 1)

Same I did for longitude function but no any message was printed; it means longitude field is missing here.

It seems 'PlainLocationField' is not working properly here.
Reply


Messages In This Thread
RE: How to auto fill latitude and longitude fields in Django2.0.6? - by PrateekG - Jun-20-2018, 10:35 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Selenium fields containing a word graham23s 3 2,928 Aug-22-2023, 12:35 PM
Last Post: Gaurav_Kumar
  Registration Form Fields rwahdan 2 1,956 Aug-09-2022, 10:35 AM
Last Post: Addweb
  How to fill text fields web forms Martinelli 1 2,087 Sep-25-2019, 11:14 PM
Last Post: Martinelli
  How to fetch latitude,longitude from location and save them separately in db(Django2) PrateekG 0 2,690 Jun-21-2018, 04:40 AM
Last Post: PrateekG

Forum Jump:

User Panel Messages

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