#NEWLINE# def load_cloud_objects( apps , schema_editor ) : #NEWLINE# #INDENT# initial_data = load_initial_data ( ) #NEWLINE# model_filter = { #NEWLINE# #INDENT# 'CloudProviderType' : 'type_name' , #NEWLINE# 'CloudRegion' : 'title' , #NEWLINE# 'CloudZone' : 'title' , #NEWLINE# 'CloudInstanceSize' : 'instance_id' , #NEWLINE# #UNINDENT# } #NEWLINE# db_alias = schema_editor . connection . alias #NEWLINE# for model in initial_data : #NEWLINE# #INDENT# model_cls = apps . get_model ( 'cloud' , model [ 'model' ] ) #NEWLINE# to_create = [ ] #NEWLINE# filter_attr = to_create [ model [ 'model' ] ] #NEWLINE# for object_data in model [ 'objects' ] : #NEWLINE# #INDENT# filtered = model_cls . objects . filter ( ** { #NEWLINE# #INDENT# filter_attr : object_data [ filter_attr ] , #NEWLINE# #UNINDENT# } ) #NEWLINE# if ( filtered . count ( ) == 0 ) : #NEWLINE# #INDENT# to_create . append ( model_cls ( ** object_data ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# for obj in filtered : #NEWLINE# #INDENT# for ( attr , val ) in object_data . items ( ) : #NEWLINE# #INDENT# setattr ( obj , attr , val ) #NEWLINE# #UNINDENT# obj . save ( ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# model_cls . objects . using ( db_alias ) . bulk_create ( to_create )