[Answered ]-Django how to override 'get_or_create' to create parent object if it doesn't exist

2👍

Your solution will introduce a bunch of sources of error/exception. Why not just follow the standard procedure?

country, created = Country.objects.get_or_create(name='myCountryName', code='myCountryCode')
state, created = State.objects.get_or_create(country=country, name='myStateName', code='myStateCode')

Leave a comment