Skip to content

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:

  1. The model must be registered with register or register_serializer. Otherwise the endpoint answers 404 with Unable to find the content type "<app_label>.<model>". The model that a relation points at does not need to be registered.
  2. resolve_choices finds the field or filter. A name that the model does not offer answers 404, and the message lists the valid names.
  3. check_permissions checks read on the model, plus list on the related model when the options are another model's rows. A missing permission answers 403. The codenames go through PERMISSION_NAMES_MAPPING. The viewset sets no permission_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 ​

NameTypeRequiredDefaultDescription
argsno
kwargsno

Source ​

server/vueda/info/viewsets.py:132

canonical ​

Signature ​

canonical(unknown)

Parameters ​

NameTypeRequiredDefaultDescription
unknownyes

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 ​

NameTypeRequiredDefaultDescription
selfyes
requestyes

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:

  1. Wraps the incoming Django HttpRequest in a REST framework Request.
  2. Performs content negotiation, authentication, permission, and throttling checks.
  3. Resolves and calls the appropriate HTTP method handler (e.g. get(), post(), put()).
  4. Handles any exceptions raised during processing and converts them into appropriate Response objects.
  5. Finalizes and returns the response with proper rendering and headers applied.

Signature ​

dispatch(self, request, app_label, model, field, args, kwargs)

Parameters ​

NameTypeRequiredDefaultDescription
selfyes
requestyes
app_labelyes
modelyes
fieldyes
argsno
kwargsno

Source ​

server/vueda/info/viewsets.py:191

get_content_type_instance ​

Signature ​

get_content_type_instance(self)

Parameters ​

NameTypeRequiredDefaultDescription
selfyes

Source ​

server/vueda/info/viewsets.py:216

get_formatted_name_lookup_expression ​

Signature ​

get_formatted_name_lookup_expression(self, queryset)

Parameters ​

NameTypeRequiredDefaultDescription
selfyes
querysetyes

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 ​

NameTypeRequiredDefaultDescription
selfyes
requestyes
argsno
kwargsno

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 ​

NameTypeRequiredDefaultDescription
selfyes

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