ModelInfoChoicesBaseViewSet
Overview
Mixin for DRF ViewSets to add 'permitted_expands' in serializer context based on the current action. It utilizes 'permit_{action}_expands' attributes of the ViewSet to determine expandable fields for each action (e.g., list, retrieve).
This replaces rest_flex_fields.FlexFieldsMixin and rest_flex_fields.FlexFieldsModelViewSet usage.
init {#init}
Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.
Signature {#init-signature}
__init__(self, args, kwargs)
Parameters {#init-parameters}
| Name | Type | Required | Description |
|---|---|---|---|
| self | yes | ||
| args | yes | ||
| kwargs | yes |
Source {#init-source}
server/vueda/info/viewsets.py:108
canonical
Signature
canonical(unknown)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| unknown | yes |
check_permissions
For fields: If the choices are hard coded on a field, then we check 'read' on the current model. If the choices are a foreign key then we check 'read' on the current model and 'list' on the related model.
For filters: If the choices are hard coded on the filter, then we check 'read' on the current model, because you may not be able to 'list' it. If the choices are a foreign key on the filter, then we check 'read' on the current model and 'list' on the related model.
If choices_permissions is None: The field carries choices but is neither a model field nor a relation, so there is no model to check against. An unknown field name never reaches this check, because resolve_choices raises Http404 for it first.
Signature
check_permissions(self, request)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| self | yes | ||
| request | yes |
Source
server/vueda/info/viewsets.py:136
dispatch
Dispatch the incoming request to the appropriate handler method.
This method implements the core request/response lifecycle for Django REST Framework views:
- Wraps the incoming Django HttpRequest in a REST framework Request.
- Performs content negotiation, authentication, permission, and throttling checks.
- Resolves and calls the appropriate HTTP method handler (e.g. get(), post(), put()).
- Handles any exceptions raised during processing and converts them into appropriate Response objects.
- Finalizes and returns the response with proper rendering and headers applied.
Signature
dispatch(self, request, app_label, model, field, args, kwargs)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| self | yes | ||
| request | yes | ||
| app_label | yes | ||
| model | yes | ||
| field | yes | ||
| args | yes | ||
| kwargs | yes |
Source
server/vueda/info/viewsets.py:165
get_content_type_instance
Signature
get_content_type_instance(self)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| self | yes |
Source
server/vueda/info/viewsets.py:190
get_formatted_name_lookup_expression
Signature
get_formatted_name_lookup_expression(self, queryset)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| self | yes | ||
| queryset | yes |
Source
server/vueda/info/viewsets.py:182
initial
Runs anything that needs to occur prior to calling the method handler.
Signature
initial(self, request, args, kwargs)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| self | yes | ||
| request | yes | ||
| args | yes | ||
| kwargs | yes |
Source
server/vueda/info/viewsets.py:172
resolve_choices
Resolve the addressed field, the permissions it requires, and the state that get_queryset needs to build the choices.
DRF calls check_permissions before it calls the handler, so resolution cannot wait for get_queryset. Subclasses store their resolved state on the instance, raise Http404 for a field the model does not offer, and tolerate repeat calls.
Signature
resolve_choices(self)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| self | yes |
Source
server/vueda/info/viewsets.py:125
choices_content_types
choices_resolved
filter_backends
object
permission_classes
queryset
serializer_class
Source
server/vueda/info/viewsets.py:102