@@ -36,7 +36,6 @@ class NumberInText(models.Model):
3636
3737 as_list = True
3838
39-
4039 # data in db
4140 value = [
4241 {
@@ -185,38 +184,41 @@ def _get_data_list(model_class, model_str, content, ctx):
185184 'template' : _get_block_tmpl (model_class , model_str )
186185 }
187186
187+ def _check_subblocks (obj ):
188+ # check if have subblocks
189+ changed = False
190+ for f in obj ._meta .fields :
191+ # isinstance(f, StreamField)
192+ if hasattr (f , 'model_list' ):
193+ changed = True
194+ value = getattr (obj , f .name )
195+ # value is StreamObject
196+ setattr (obj , f .name , value .copy ())
197+ if changed :
198+ obj .save ()
199+
188200def _copy (model_class , model_str , content , ctx ):
189201 as_list = ctx ['as_list' ]
190- if as_list :
191- id = []
192- for obj in content :
193- obj .pk = None
194- obj .save ()
195- id .append (obj .pk )
196- else :
197- content .pk = None
198- content .save ()
199- id = content .pk
200-
201- # check if have subblocks
202- changed = False
203- for f in content ._meta .fields :
204- # isinstance(f, StreamField)
205- if hasattr (f , 'model_list' ):
206- changed = True
207- value = getattr (content , f .name )
208- # value is StreamObject
209- new_value = value .copy ()
210- setattr (content , f .name , new_value )
211- if changed :
212- content .save ()
213-
214- return dict (
202+ resp = dict (
215203 unique_id = uuid4 ().hex [:6 ],
216204 model_name = model_str ,
217- id = id ,
218205 options = ctx ['options' ]
219206 )
207+ if not model_class ._meta .abstract :
208+ if as_list :
209+ id = []
210+ for obj in content :
211+ obj .pk = None
212+ obj .save ()
213+ id .append (obj .pk )
214+ _check_subblocks (obj )
215+ else :
216+ content .pk = None
217+ content .save ()
218+ id = content .pk
219+ _check_subblocks (content )
220+ resp ['id' ] = id
221+ return resp
220222
221223def get_streamblocks_models ():
222224 streamblock_models = []
0 commit comments