fix issue with OneToOne not being set on from
This commit is contained in:
parent
ed88a2f2b3
commit
4d0f471cfc
@ -3,16 +3,22 @@ def merge(from_obj, to_obj):
|
|||||||
for related in from_obj._meta.get_all_related_objects():
|
for related in from_obj._meta.get_all_related_objects():
|
||||||
accessor_name = related.get_accessor_name()
|
accessor_name = related.get_accessor_name()
|
||||||
varname = related.field.name
|
varname = related.field.name
|
||||||
field = getattr(from_obj, accessor_name)
|
|
||||||
if related.multiple:
|
if related.multiple:
|
||||||
|
field = getattr(from_obj, accessor_name)
|
||||||
field.all().update(**{varname: to_obj})
|
field.all().update(**{varname: to_obj})
|
||||||
elif related.one_to_one:
|
elif related.one_to_one:
|
||||||
try:
|
try:
|
||||||
getattr(to_obj, accessor_name)
|
field = getattr(from_obj, accessor_name)
|
||||||
|
try:
|
||||||
|
getattr(to_obj, accessor_name)
|
||||||
|
except Exception as e:
|
||||||
|
# doesn't exist, safe to overwrite
|
||||||
|
setattr(field, varname, to_obj)
|
||||||
|
field.save()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# doesn't exist, safe to overwrite
|
# from_obj one to one isn't set, skip
|
||||||
setattr(field, varname, to_obj)
|
pass
|
||||||
field.save()
|
|
||||||
else:
|
else:
|
||||||
import pdb; pdb.set_trace()
|
import pdb; pdb.set_trace()
|
||||||
raise Exception('unknown code path')
|
raise Exception('unknown code path')
|
||||||
|
Loading…
Reference in New Issue
Block a user