akvo.rsr.management.commands.merge_organisations module

class akvo.rsr.management.commands.merge_organisations.Command(stdout=None, stderr=None, no_color=False, force_color=False)[source]

Bases: BaseCommand

add_arguments(parser)[source]

Entry point for subclassed commands to add custom arguments.

handle(*args, **options)[source]

The actual logic of the command. Subclasses must implement this method.

help = 'Script for merging organisations'
akvo.rsr.management.commands.merge_organisations.diff_objects(primary, alias, no_prompt)[source]

Find which fields differ between the two objects.

akvo.rsr.management.commands.merge_organisations.discrimine(pred, sequence)[source]

Split a collection in two collections using a predicate.

>>> discrimine(lambda x: x < 5, [3, 4, 5, 6, 7, 8])
... ([3, 4], [5, 6, 7, 8])
akvo.rsr.management.commands.merge_organisations.get_generic_fields()[source]

Return a list of all GenericForeignKeys in all models.

akvo.rsr.management.commands.merge_organisations.merge(primary_object, alias_object)[source]

Merge several model instances into one, the primary_object. Use this function to merge model objects and migrate all of the related fields from the alias objects the primary object. Usage:

from django.contrib.auth.models import User primary_user = User.objects.get(email=’good@example.com’) duplicate_user = User.objects.get(email=’good+duplicate@example.com’) merge(primary_user, duplicate_user)

Based on: https://djangosnippets.org/snippets/382/