'Deletes all the objects in the database that are not in objects_to_keep.
- objects_to_keep: A map where the keys are classes, and the values are a
set of the objects of that class we should keep.'

def remove_objects_not_in(self, objects_to_keep, verbosity):

    for class_ in objects_to_keep.keys():
        current = class_.objects.all()
        current_ids = set([x.pk for x in current])
        keep_ids = set([x.pk for x in objects_to_keep[class_]])
        remove_these_ones = current_ids.difference(keep_ids)
        if remove_these_ones:
            for obj in current:
                if (obj.pk in remove_these_ones):
                    obj.delete()
                    if (verbosity >= 2):
                        print ('Deleted    object:    %s' % six.u(obj))
        if ((verbosity > 0) and remove_these_ones):
            num_deleted = len(remove_these_ones)
            if (num_deleted > 1):
                type_deleted = six.u(class_._meta.verbose_name_plural)
            else:
                type_deleted = six.u(class_._meta.verbose_name)
            print ('Deleted    %s    %s' % (str(num_deleted), type_deleted))
