django-address
django-address copied to clipboard
Address Form field only populates if full address is provided.
I am noticing an issue where the Address form field will only populate if the Address Instance of the AddressField has a full address populated. This issue seems to be originating from the to_dict
method on the Address
model.
In my instance, I am only populating the Country. I assume this means I do not have a Locality
or State
causing the country part of the below logic to not run.
def as_dict(self):
ad = dict(
street_number=self.street_number,
route=self.route,
raw=self.raw,
formatted=self.formatted,
latitude=self.latitude if self.latitude else "",
longitude=self.longitude if self.longitude else "",
)
if self.locality:
ad["locality"] = self.locality.name
ad["postal_code"] = self.locality.postal_code
if self.locality.state:
ad["state"] = self.locality.state.name
ad["state_code"] = self.locality.state.code
if self.locality.state.country:
ad["country"] = self.locality.state.country.name
ad["country_code"] = self.locality.state.country.code
return ad