ModelInfoFilterSetChoicesViewSet
Overview
List the choices of one filter in the filterset_class of a model's canonical viewset.
The field URL segment names a filter of that filterset. A model with no canonical viewset, or a viewset with no filterset_class, answers 404, as does a name that the filterset lacks. A filter with a queryset (ModelChoiceFilter, ModelMultipleChoiceFilter) needs read on the model and list on the model of the queryset that get_queryset(request) returns. Every other filter needs read on the model.
The endpoint reads the same rows that the viewset's list action reads. It calls the viewset's get_queryset() as a list request with this request, an empty kwargs, and action = "list". filter_rows_for_user then keeps the rows that the user may list, by the model's row-level and workflow state rules for the list permission. The request's query parameters build the filterset over those rows. What the options are depends on the filter:
- A filter with a
querysetreturns the rows of that queryset that the matching rows of the model reference and that the user may list, by the same rule on the related model. A related row that the user may not list is left out, even when a matching row references it. The value is the primary key as a string. The label comes from the first of these that the related model provides: aget_formatted_name()method, the column that a stringformatted_name_lookup_expressionnames, or theformatted_namecolumn. Options are sorted by label. AllValuesFilterandAllValuesMultipleFilterreturn the distinct values of the column in the matching rows, sorted by value. Each label is the value as a string.- A filter with static choices (
ChoiceFilter,TypedChoiceFilter,BooleanFilter, and similar) returns the choices of its form widget.
For the first two kinds, the matching rows are those that the request's other filter parameters select. The filter's own parameter is left out, so it never narrows them. For static choices, the other parameters have no effect. The filter's own parameter narrows static choices only when the filter's lookup_expr is contains, icontains, startswith, or istartswith. The endpoint then keeps each choice whose value contains, or starts with, the parameter, ignoring case for all four. Labels are not compared.
Static and column-value options omit empty values (EMPTY_VALUES), because a request without the filter's parameter already means "no filter".
get_list_queryset
Return the queryset that the registered viewset's get_queryset() builds for a list request.
The viewset instance carries this request, action = "list", detail = False, and empty args and kwargs, so a get_queryset() that reads self.request, self.action, or self.kwargs builds the queryset of the registration's list route.
Signature
get_list_queryset(self)
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| self | yes |
Source
server/vueda/info/viewsets.py:584
get_listed_rows
Return the rows that the registered viewset's list action returns for this request's other filters.
The rows start from :meth:get_list_queryset. filter_rows_for_user keeps the rows that the user may list. The filterset then applies every query parameter except the addressed filter's own, so that filter never narrows its own choices.
Signature
get_listed_rows(self)
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| self | yes |
Source
server/vueda/info/viewsets.py:601
get_queryset
Returns a queryset if the field is a relation. Return a list if the field is not a relation.
Dynamic choices come from the rows that the registered viewset's list action reads: its get_queryset(), then the rows that filter_rows_for_user keeps for the list permission by row-level rules and workflow state rules. A value or related key found only on a row outside those rows is not offered. A queryset-backed filter's choices are also rows that the user may list on the related model, within the filter's own queryset, so a listed main row that references a hidden related row does not make that row a choice. Static declared choices read no rows.
Signature
get_queryset(self)
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| self | yes |
Source
server/vueda/info/viewsets.py:617
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:522
validate_queryset
Signature
validate_queryset(self, filterset_instance, filter_mapping)
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| self | yes | |||
| filterset_instance | yes | |||
| filter_mapping | yes |
Source
server/vueda/info/viewsets.py:512
basename
description
detail
name
serializer_class
suffix
Source
server/vueda/info/viewsets.py:471