def forwards(apps, schema_editor):
    """Set same_as_priority for all same-as contacts """
    same_as_model = apps.get_model('Crm', 'SameAs')
    for same_as in same_as_model.objects.all():
        if same_as.contact_set.count() == 1:
            for contact in same_as.contact_set.all():
                contact.same_as = None
                contact.same_as_priority = 0
                contact.save()
        if same_as.contact_set.count() <= 1:
            same_as.delete()
