Browse Source

Admin | Udelej orga priradi skupinu a ne opravneni

Skupina org ma opravneni org by default, tedy se podedi.
export_seznamu_prednasek
parent
commit
749d16ee89
  1. 7
      seminar/admin.py

7
seminar/admin.py

@ -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)

Loading…
Cancel
Save