Bart Friederichs
Bart Friederichs

Reputation: 33491

Permission does not show in admin page

I have added an app to my existing django site and to view it, I created an extra permission overview.view. But, I do not see it in my admin page, so I can also not assign this permission to any user. I think I have all files setup correctly, but I guess I am missing something. I have all the same files in the overview folder as I have in other working folders.

I do see the page, but somehow I am not logged in either.

This is my urls.py:

from django.urls import path
from . import views

urlpatterns = [
    path('', views.index, name='index')    
]

models.py:

from django.db import models

class Overview(models.Model):
    class Meta:
        permissions = (
            ('view', "May view the overview"),
        )

and (part of) settings.py

INSTALLED_APPS = [
    'overview.apps.OverviewConfig'
]

Upvotes: 1

Views: 464

Answers (1)

Abdul Aziz Barkat
Abdul Aziz Barkat

Reputation: 21787

Permissions are stored in the database and so when you add or remove them via the Meta for the model the same is not of course automatically reflected in the database. Permissions are added post the migrations via a post_migrate signal connected from the auth apps appconfig's ready method. See the source code [GitHub]:

post_migrate.connect(
    create_permissions,
    dispatch_uid="django.contrib.auth.management.create_permissions"
)

Hence when one makes changes to the permissions one needs to run makemigrations and migrate to make sure they are added to the database.

Upvotes: 1

Related Questions