ModelInfoChoicesBaseViewSet
Overview
Base of the two choice endpoints, which list the {label, value} options of one field or filter on a registered model.
The URL names the model by app_label and model (the lowercase model name that its content type stores) and the field or filter by field. A request passes three checks in order:
- The model must be registered with
registerorregister_serializer. Otherwise the endpoint answers 404 withUnable to find the content type "<app_label>.<model>".The model that a relation points at does not need to be registered. resolve_choicesfinds the field or filter. A name that the model does not offer answers 404, and the message lists the valid names.check_permissionschecksreadon the model, plusliston the related model when the options are another model's rows. A missing permission answers 403. The codenames go throughPERMISSION_NAMES_MAPPING. The viewset sets nopermission_classes, so these are the only permission checks.
Every value is a string, whatever the column type. Responses are paginated like other VUEDA lists. The search and ordering filter backends are removed, so the endpoints take no search or ordering parameter.
__init__
Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.
Signature
__init__(args, kwargs)
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| args | no | |||
| kwargs | no |
Source
server/vueda/info/viewsets.py:132
canonical
Signature
canonical(unknown)
Parameters
| Name | Type | Required | Default | 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.
For serializer-only fields (neither a model field nor a model relation): We check 'read' on the current model, and for a related field also 'list' on the model of the field's queryset.
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 | Default | Description |
|---|---|---|---|---|
| self | yes | |||
| request | yes |
Source
server/vueda/info/viewsets.py:160
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 | Default | Description |
|---|---|---|---|---|
| self | yes | |||
| request | yes | |||
| app_label | yes | |||
| model | yes | |||
| field | yes | |||
| args | no | |||
| kwargs | no |
Source
server/vueda/info/viewsets.py:191
get_content_type_instance
Signature
get_content_type_instance(self)
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| self | yes |
Source
server/vueda/info/viewsets.py:216
get_formatted_name_lookup_expression
Signature
get_formatted_name_lookup_expression(self, queryset)
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| self | yes | |||
| queryset | yes |
Source
server/vueda/info/viewsets.py:208
initial
Runs anything that needs to occur prior to calling the method handler.
Signature
initial(self, request, args, kwargs)
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| self | yes | |||
| request | yes | |||
| args | no | |||
| kwargs | no |
Source
server/vueda/info/viewsets.py:198
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 | Default | Description |
|---|---|---|---|---|
| self | yes |
Source
server/vueda/info/viewsets.py:149
choices_content_types
choices_resolved
filter_backends
object
permission_classes
queryset
serializer_class
Source
server/vueda/info/viewsets.py:104