i have problem with groups and permission in django. I want to create a group of users and admin. In django panel admin i see permission which i need:
- app | user | Can add user
- app | user | Can change user
- app | user | Can delete user
- app | user | Can view user
I need create group "user" and "admin" then add perm to user "Can view user" and to admin all this perms and this is need to do with migration.
My already code i suposed is totally stupid
# Generated by Django 4.0.3 on 2022-09-11 10:33
from django.db import migrations, transaction
from django.contrib.auth.models import Group, Permission
def add_group_permissions(a,b):
group, created = Group.objects.get_or_create(name='user')
try:
with transaction.atomic():
group.permissions.add(can_view_user)
group.save()
except InterruptedError:
group.delete()
class Migration(migrations.Migration):
dependencies = [
('app', '0001_initial'),
]
operations = [
migrations.RunPython(add_group_permissions),
]
If anyone can help, i need that.