I’m pulling in data from an external place database that returns JSON of information about locations. I’d like to save as much info as possible, but not every row has all info. I’d like to:
location, created = Location.objects.get_or_create(
name=info['name'],
lat=info['location']['lat'],
lng=info['location']['lng'],
address=info['location']['address'],
)
but for some locations, the address isn’t present, so this would throw an error. If there a short way to do this and avoid a huge string of if .. else statements?
You can use
dictmethodget