kpsul/kfet/auth/fields.py

25 lines
798 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
2020-08-03 19:06:48 +02:00
from .models import KFetPermission
class KFetPermissionsField(forms.ModelMultipleChoiceField):
def __init__(self, *args, **kwargs):
2020-08-03 20:35:56 +02:00
kwargs.setdefault("queryset", KFetPermission.objects.all())
2020-08-17 16:17:28 +02:00
kwargs.setdefault("widget", forms.CheckboxSelectMultiple)
2020-08-03 19:06:48 +02:00
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))
2020-08-17 16:17:28 +02:00
kwargs.setdefault("widget", forms.SelectMultiple)
2020-08-03 19:06:48 +02:00
super().__init__(*args, **kwargs)
def label_from_instance(self, obj):
return obj.name