Admin | Udelej orga priradi skupinu a ne opravneni

Skupina org ma opravneni org by default, tedy se podedi.
This commit is contained in:
Tomas 'Jethro' Pokorny 2021-02-16 22:00:42 +01:00
parent 644b37d08b
commit 749d16ee89

View file

@ -1,5 +1,5 @@
from django.contrib import admin from django.contrib import admin
from django.contrib.auth.models import Permission from django.contrib.auth.models import Group
from django.db import models from django.db import models
from django.forms import widgets from django.forms import widgets
@ -32,11 +32,12 @@ class OsobaAdmin(admin.ModelAdmin):
synchronizuj_maily.short_description = "Synchronizuj vybraným osobám e-maily do uživatelů" synchronizuj_maily.short_description = "Synchronizuj vybraným osobám e-maily do uživatelů"
def udelej_orgem(self,request,queryset): def udelej_orgem(self,request,queryset):
org_perm = Permission.objects.filter(codename__exact='org').first() org_group = Group.objects.get(name='org')
print(queryset) print(queryset)
for o in queryset: for o in queryset:
user = o.user user = o.user
user.user_permissions.add(org_perm) print(user)
user.groups.add(org_group)
user.is_staff = True user.is_staff = True
user.save() user.save()
org = m.Organizator.objects.create(osoba=o) org = m.Organizator.objects.create(osoba=o)