File tree Expand file tree Collapse file tree 1 file changed +8
-6
lines changed Expand file tree Collapse file tree 1 file changed +8
-6
lines changed Original file line number Diff line number Diff line change @@ -127,9 +127,10 @@ def populate_initial_data(self, content_types):
127127 """
128128 for ct in content_types :
129129 model = ct .model_class ()
130- for obj in model .objects .exclude (** {f'custom_field_data__contains' : self .name }):
131- obj .custom_field_data [self .name ] = self .default
132- obj .save ()
130+ instances = model .objects .exclude (** {f'custom_field_data__contains' : self .name })
131+ for instance in instances :
132+ instance .custom_field_data [self .name ] = self .default
133+ model .objects .bulk_update (instances , ['custom_field_data' ], batch_size = 100 )
133134
134135 def remove_stale_data (self , content_types ):
135136 """
@@ -138,9 +139,10 @@ def remove_stale_data(self, content_types):
138139 """
139140 for ct in content_types :
140141 model = ct .model_class ()
141- for obj in model .objects .filter (** {f'custom_field_data__{ self .name } __isnull' : False }):
142- del (obj .custom_field_data [self .name ])
143- obj .save ()
142+ instances = model .objects .filter (** {f'custom_field_data__{ self .name } __isnull' : False })
143+ for instance in instances :
144+ del (instance .custom_field_data [self .name ])
145+ model .objects .bulk_update (instances , ['custom_field_data' ], batch_size = 100 )
144146
145147 def rename_object_data (self , old_name , new_name ):
146148 """
You can’t perform that action at this time.
0 commit comments