I am trying to migrate my models to use Guardian permissions. At this point I have:
class Data(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
class Meta:
permissions = (
('view', 'View'),
('edit', 'Edit'),
('owner', 'Owner'),
)
I created one migration that added the new permissions, and in a custom migration I am trying to assign the permissions like this:
def assignDataPermissions(apps, schema_editor):
Data = apps.get_model('api', 'Data')
for data in Data.objects.all():
assign_perm('api.owner', data.user, data)
class Migration(migrations.Migration):
dependencies = [
('api', '0169_auto_20180304_1619'),
]
operations = [
migrations.RunPython(assignDataPermissions)
]
This fails with
guardian.exceptions.NotUserNorGroup: User/AnonymousUser or Group instance is required (got EmailUser object)
.
Is there a better/proper way of migrating to Guardian? If not, how do I make it see my custom User class?