from django import forms from .models import Group, Permission class GroupsField(forms.ModelMultipleChoiceField): def __init__(self, **kwargs): kwargs.setdefault('queryset', Group.objects.all()) kwargs.setdefault('widget', forms.CheckboxSelectMultiple) super().__init__(**kwargs) class BasePermissionsField(forms.ModelMultipleChoiceField): def __init__(self, **kwargs): kwargs.setdefault('widget', forms.CheckboxSelectMultiple) super().__init__(**kwargs) def label_from_instance(self, obj): return obj.name class CorePermissionsField(BasePermissionsField): def __init__(self, **kwargs): kwargs.setdefault('queryset', Permission.kfetcore.all()) super().__init__(**kwargs)