Skip to content

Commit 59b2ad5

Browse files
committed
Minor docs tweaks
1 parent e2587c7 commit 59b2ad5

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

docs/api-guide/serializers.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -507,9 +507,11 @@ Model fields which have `editable=False` set, and `AutoField` fields will be set
507507

508508
---
509509

510-
**Note**: There is a special-case where a read-only field is part of a `unique_together` constraint at the model level. Here you **must** specify the field explicitly and provide a valid default value.
510+
**Note**: There is a special-case where a read-only field is part of a `unique_together` constraint at the model level. In this case the field is required by the serializer class in order to validate the constraint, but should also not be editable by the user.
511511

512-
A common example of this is a read-only relation to the currently authenticated `User` which is `unique_together` with another identifier. In this case you would declare the user field like so:
512+
The right way to deal with this is to specify the field explicitly on the serializer, providing both the `read_only=True` and `default=…` keyword arguments.
513+
514+
One example of this is a read-only relation to the currently authenticated `User` which is `unique_together` with another identifier. In this case you would declare the user field like so:
513515

514516
user = serializers.PrimaryKeyRelatedField(read_only=True, default=serializers.CurrentUserDefault())
515517

0 commit comments

Comments
 (0)