1
votes

I have custom permissions in my meta:

class Meta(): #extra bit of info
    model = User
    permissions = (
        ("has_uploaded", ("Has uploaded")),
        ("is_authenticated", ("Is authenticated")),
    )
    fields = ('email','emailConfirm','password1','biography','research_place','studies')

however when I try to do

is_auth_perm = Permission.objects.get(codename='is_authenticated')
request.user.user_permissions.add("is_auth_perm")

in my views I get the error that the permission does not exist, even after i do migrations and syncdb. am i doing something wrong?

1
You're using is_auth_perm as a string, is this a typo here or in your code .add("is_auth_perm")? - danielcorreia
@danielcorreia thanks for noticing that, but that is not the entire error because the error is specifically on the line with is_auth_perm = etc. - swedishfished

1 Answers

2
votes

Did you add the permission to your model after first initializing the database? If so, the new permissions are not added to the database automatically even if you migrate.

To add the new permissions, you could use the update_permissions manage.py command from the django-extensions package.