Django model permissions not picked up on admin
Asked Answered
B

3

14

I've added permission to my model and I would like to create a group in admin that uses this permission.

The problem is that the new permission is not listed in the permissions list.

is there something I need to do to add it to that list?

    class Meta:
        permissions = (
            ("add_remove_job", "Can add/remove jobs"),
        )

SOLUTION: It is a known limitation of South, the solution is to do syncdb --all

Budde answered 26/4, 2013 at 12:5 Comment(1)
Since you found your solution, you should select the answer that gave you the solution.Lollipop
M
15

try:

manage.py syncdb --all

Otherwise, You can force django to generate permissions for a particular app:

from django.contrib.auth.management import create_permissions
from django.apps import apps

create_permissions(apps.get_app_config('my_app_name'))

This will do all models in the app. You can substitute a list of model class objects instead of 'get_models()' if you only want a subset.

Michi answered 19/6, 2013 at 23:10 Comment(2)
Unfortunatelly doesn't work with Django 1.7 anymore. You have to from django.apps import apps and then call create_permissions(apps.get_app_config('my_app_name')) but (I think if you use migrations) it will return after if not router.allow_migrate(using, Permission) without doing anything.Leisured
Important the --all flag for apps using South! Thanks.Wiener
H
3

What you need to do is a syncdb each time you add/modify a permission for a model.

 python manage.py syncdb
Ha answered 26/4, 2013 at 12:15 Comment(1)
did not work, I tried to syncdb I'm using South for DB migration if this means something.Budde
D
-5
python manage.py migrate --fake
Dalmatic answered 9/8, 2016 at 10:28 Comment(1)
How does it relate to the question?Mendicant

© 2022 - 2024 — McMap. All rights reserved.