authentik.enterprise.requests.api.request_rule_child_bindings
1from rest_framework.viewsets import ModelViewSet 2 3from authentik.core.api.used_by import UsedByMixin 4from authentik.core.api.utils import ModelSerializer 5from authentik.enterprise.requests.models import RequestRuleChildBinding 6 7 8class RequestRuleChildBindingSerializer(ModelSerializer): 9 10 class Meta: 11 model = RequestRuleChildBinding 12 fields = [ 13 "uuid", 14 "binding", 15 "target", 16 ] 17 18 19class RequestRuleChildBindingViewSet(UsedByMixin, ModelViewSet): 20 21 queryset = RequestRuleChildBinding.objects.all() 22 serializer_class = RequestRuleChildBindingSerializer 23 filterset_fields = ["binding", "target"] 24 ordering = ["binding"] 25 search_fields = []
9class RequestRuleChildBindingSerializer(ModelSerializer): 10 11 class Meta: 12 model = RequestRuleChildBinding 13 fields = [ 14 "uuid", 15 "binding", 16 "target", 17 ]
A ModelSerializer is just a regular Serializer, except that:
- A set of default fields are automatically populated.
- A set of default validators are automatically populated.
- Default
.create()and.update()implementations are provided.
The process of automatically determining a set of serializer fields based on the model fields is reasonably complex, but you almost certainly don't need to dig into the implementation.
If the ModelSerializer class doesn't generate the set of fields that
you need you should either declare the extra/differing fields explicitly on
the serializer class, or simply use a Serializer class.
class
RequestRuleChildBindingSerializer.Meta:
11 class Meta: 12 model = RequestRuleChildBinding 13 fields = [ 14 "uuid", 15 "binding", 16 "target", 17 ]
model =
<class 'authentik.enterprise.requests.models.RequestRuleChildBinding'>
class
RequestRuleChildBindingViewSet(authentik.core.api.used_by.UsedByMixin, rest_framework.viewsets.ModelViewSet):
20class RequestRuleChildBindingViewSet(UsedByMixin, ModelViewSet): 21 22 queryset = RequestRuleChildBinding.objects.all() 23 serializer_class = RequestRuleChildBindingSerializer 24 filterset_fields = ["binding", "target"] 25 ordering = ["binding"] 26 search_fields = []
Mixin to add a used_by endpoint to return a list of all objects using this object
serializer_class =
<class 'RequestRuleChildBindingSerializer'>