swedishfished
swedishfished

Reputation: 399

Django custom permissions not being recognized?

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?

Upvotes: 1

Views: 767

Answers (1)

Tim
Tim

Reputation: 1357

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.

Upvotes: 2

Related Questions