gestioCOF/kfet/auth/fields.py

26 lines
832 B
Python
Raw Normal View History

from django import forms
2020-08-03 19:06:48 +02:00
from django.contrib.auth.models import Group
from django.forms import widgets
2020-08-03 19:06:48 +02:00
from .models import KFetPermission
class KFetPermissionsField(forms.ModelMultipleChoiceField):
def __init__(self, *args, **kwargs):
2020-08-03 19:06:48 +02:00
kwargs.setdefault("queryset", KFetPermission.kfet.all())
kwargs.setdefault("widget", widgets.CheckboxSelectMultiple)
super().__init__(*args, **kwargs)
def label_from_instance(self, obj):
return obj.name
class KFetGroupsField(forms.ModelMultipleChoiceField):
def __init__(self, *args, **kwargs):
kwargs.setdefault("queryset", Group.objects.filter(kfetgroup__isnull=False))
kwargs.setdefault("widget", widgets.SelectMultiple)
super().__init__(*args, **kwargs)
def label_from_instance(self, obj):
return obj.name