diff options
Diffstat (limited to 'ishtar_common/model_merging.py')
-rw-r--r-- | ishtar_common/model_merging.py | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/ishtar_common/model_merging.py b/ishtar_common/model_merging.py index a390f233c..3f392f596 100644 --- a/ishtar_common/model_merging.py +++ b/ishtar_common/model_merging.py @@ -22,7 +22,7 @@ def get_models(): @transaction.atomic def merge_model_objects(primary_object, alias_objects=[], keep_old=False): """ - Use this function to merge model objects (i.e. Users, Organizations, Polls, + Use this function to merge model objects (i.e. Users, Organizations, etc.) and migrate all of the related fields from the alias objects to the primary object. @@ -81,9 +81,14 @@ def merge_model_objects(primary_object, alias_objects=[], keep_old=False): related_objects = getattr(alias_object, alias_varname) except ObjectDoesNotExist: continue - for obj in related_objects.all(): - setattr(obj, obj_varname, primary_object) - obj.save() + if not hasattr(related_objects, 'all'): + # one to one field + setattr(related_objects, obj_varname, primary_object) + related_objects.save() + else: + for obj in related_objects.all(): + setattr(obj, obj_varname, primary_object) + obj.save() # Migrate all many to many references from alias object to primary # object. |