---
url: "https://vueda.dev/v3/reference/api/py/vueda.info.viewsets/ModelInfoChoicesViewSet.md"
title: "ModelInfoChoicesViewSet"
---

# ModelInfoChoicesViewSet

## Overview

List the choices of one field on a model's canonical serializer.

The ``field`` URL segment names a field of that serializer. A field without ``choices`` answers
404. The permissions depend on what backs the field:

- A model field needs ``read`` on the model.
- A model relation needs ``read`` on the model and ``list`` on the related model.
- A serializer-only field, which is neither, needs ``read`` on the model. When it has a
  ``queryset``, it also needs ``list`` on that queryset's model.

A field with static choices (a ``ChoiceField``, or a model field with ``choices``) returns every
entry, sorted by label, with the value converted to a string. Blank entries stay in the list,
since a create or update form can offer them.

A related field (``PrimaryKeyRelatedField``, ``SlugRelatedField``, or a many-related field)
returns the rows of the serializer field's queryset. The value is the primary key as a string,
or the ``slug_field`` value for a ``SlugRelatedField``. The label is the related model's
formatted name, and options are sorted by it. The label comes from the first of these that the
related model provides:

1. A ``get_formatted_name()`` method, called on each row.
2. The column that a string ``formatted_name_lookup_expression`` names.
3. The ``formatted_name`` column.

A related model with none of the three raises ``FieldError``.

## `get_queryset` {#get_queryset}

Returns a queryset if the field is a relation.
Return a list if the field is not a relation.

### Signature {#get_queryset-signature}

`get_queryset(self)`

#### Parameters {#get_queryset-parameters}

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| self |  | yes |  |  |

### Source {#get_queryset-source}

`server/vueda/info/viewsets.py:346`

## `has_choices` {#has_choices}

Report whether a serializer field offers choices, without materializing them.

``RelatedField.choices`` and ``ManyRelatedField.choices`` are properties that read the
related queryset, so a plain ``hasattr`` on the instance reads the related table. Testing
the class answers the same question for every DRF field without a query. The instance test
stays for a field that assigns ``choices`` in ``__init__`` instead of declaring a property.

### Signature {#has_choices-signature}

`has_choices(self, field)`

#### Parameters {#has_choices-parameters}

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| self |  | yes |  |  |
| <span id="has_choices-param-field">field</span> |  | yes |  |  |

### Source {#has_choices-source}

`server/vueda/info/viewsets.py:258`

## `resolve_choices` {#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-signature}

`resolve_choices(self)`

#### Parameters {#resolve_choices-parameters}

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| self |  | yes |  |  |

### Source {#resolve_choices-source}

`server/vueda/info/viewsets.py:287`

## `validate_queryset` {#validate_queryset}

### Signature {#validate_queryset-signature}

`validate_queryset(self, serializer, fields)`

#### Parameters {#validate_queryset-parameters}

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| self |  | yes |  |  |
| <span id="validate_queryset-param-serializer">serializer</span> |  | yes |  |  |
| <span id="validate_queryset-param-fields">fields</span> |  | yes |  |  |

### Source {#validate_queryset-source}

`server/vueda/info/viewsets.py:269`

## `basename` {#basename}

## `description` {#description}

## `detail` {#detail}

## `name` {#name}

## `serializer_class` {#serializer_class}

## `suffix` {#suffix}

## Source

`server/vueda/info/viewsets.py:227`
