gestioCOF/kfet/auth/fields.py
Ludovic Stephan 2d36c85085 Fix dev data
2020-09-07 14:57:41 +02:00

25 lines
835 B
Python

from django import forms
from django.contrib.auth.models import Group
from django.forms import widgets
from .models import KFetPermission
class KFetPermissionsField(forms.ModelMultipleChoiceField):
def __init__(self, *args, **kwargs):
kwargs.setdefault("queryset", KFetPermission.objects.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