---
url: "https://vueda.dev/v3/reference/api/py/vueda.core.serializers/ModelPrimaryKeyValueField.md"
title: "ModelPrimaryKeyValueField"
---

# ModelPrimaryKeyValueField

## Overview

Converts one primary key value to the value that a ``pk`` filter on ``model`` expects.

The model's primary key field does the conversion, so a UUID, string, or other key type
converts the way the database lookup needs it. A composite key arrives as its JSON array
string, such as ``'["1", "42"]'``, the same form that the detail route takes. It converts to a
tuple of column values. A value that the key field cannot convert fails as ``invalid``.

## `__init__` {#--init--}

When a field is instantiated, we store the arguments that were used,
so that we can present a helpful representation of the object.

### Signature {#--init---signature}

`__init__(args, kwargs)`

#### Parameters {#--init---parameters}

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| <span id="--init---param-args">args</span> |  | no |  |  |
| <span id="--init---param-kwargs">kwargs</span> |  | no |  |  |

### Source {#--init---source}

`.venv/lib/python3.12/site-packages/rest_framework/fields.py:615`

## `to_internal_value` {#to_internal_value}

Transform the *incoming* primitive data into a native value.

### Signature {#to_internal_value-signature}

`to_internal_value(self, data)`

#### Parameters {#to_internal_value-parameters}

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

### Source {#to_internal_value-source}

`server/vueda/core/serializers/__init__.py:82`

## `to_representation` {#to_representation}

Transform the *outgoing* native value into primitive data.

### Signature {#to_representation-signature}

`to_representation(self, value)`

#### Parameters {#to_representation-parameters}

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

### Source {#to_representation-source}

`server/vueda/core/serializers/__init__.py:96`

## `default_error_messages` {#default_error_messages}

## `model` {#model}

## Source

`server/vueda/core/serializers/__init__.py:66`
