Shoaib Ijaz
Shoaib Ijaz

Reputation: 5587

Django: How to manage groups and permission without using default admin

I am working on Django project as per requirements I need to manage users, groups and permissions in custom template. So I am not using default admin dashboard.

I have completed user creation module, now I want to assign permissions and groups to a user.

I have not override or customize any auth Model yet. But in future I need to Customize User Model e.g some additional fields etc.

First thing that comes in my mind to delete all permissions from auth_permission table and add my custom permissions.

So I have to do following things:

  1. Create group
  2. Permissions List
  3. Assign permissions to each group
  4. Assign group or permissions to each user

I have some concerns about these things.

Needs some healthy tips.

updated: I want to show admin only my custom permissions like perm1, perm2. Currently there are others many permissions.

Thank you

Upvotes: 2

Views: 2772

Answers (1)

CrazyCasta
CrazyCasta

Reputation: 28332

"If I have deleted all permissions, will it be OK for project?"

If you try to get rid of existing permissions django might just recreate them, or you may run into trouble when creating new models. I'm not sure on the details of when the get created/recreated, but django has default permissions for every model you create.

"Django functions for validate permissions like has_perm would work?"

As long as you create permissions either by Programmatically creating permissions or by putting Custom Permissions in a model's Meta class you should be able to use them like any other permissions. Specifically I mean you should be able to use user.has_perm and the permission_required decorator.

"Can I do some different thing for it?"

If you want to only show certain permissions from something like user.user_permissions I'd suggest filtering the results you get instead of trying to get rid of existing permissions. Something like the following would be appropriate:

filter_show_permissions = ["perm_a", "perm_b", ...]
filtered_permissions = [perm for perm in user.user_permissions
                        if perm in filter_show_permissions]

Upvotes: 2

Related Questions