Add tip about using values() to exclude required fields

This commit is contained in:
johnthagen
2021-10-06 13:44:12 -04:00
committed by GitHub
parent 94d49c66f2
commit a6c9281b6a

View File

@ -109,6 +109,9 @@ assert all_cars[0].manufacturer.founded == 1937
Mandatory fields cannot be excluded as it will raise `ValidationError`, to
exclude a field it has to be nullable.
The `values()` method can be used to exclude mandatory fields, though data will
be returned as a `dict`.
You cannot exclude mandatory model columns - `manufacturer__name` in this example.
```python
@ -274,6 +277,9 @@ await Car.objects.select_related('manufacturer').exclude_fields([{'company': {'n
Mandatory fields cannot be excluded as it will raise `ValidationError`, to
exclude a field it has to be nullable.
The `values()` method can be used to exclude mandatory fields, though data will
be returned as a `dict`.
!!!tip
Pk column cannot be excluded - it's always auto added even if explicitly
excluded.