Django/python: How To Iterate Through A List In A Dictionary For Migration/migrate Data
I’m trying to set up migration files to load values into my tables. I am creating countries/states in my tables. I would like to set it up in a way that I can put each country in
Solution 1:
I guess the problem the way you initially are trying to approach this task. I think you should update your dictionary:
canada = {
'country': import_country,
'states': import_states,
}
Keep in mind that a key should be an immutable object.
for country in list_of_countries:
import_country = country['country']
states = country['states']
current_country = Country.objects.get_or_create(
country_code=c[0],
country_name=c[1]
)
current_country.states = states
I am not sure what you are trying to achieve, but if you provide a better description I can update my answer.
Post a Comment for "Django/python: How To Iterate Through A List In A Dictionary For Migration/migrate Data"