Merge pull request #366 from johnthagen/patch-1

Add tip about using values() to exclude required fields
This commit is contained in:
collerek
2021-10-07 09:14:24 +02:00
committed by GitHub

View File

@ -109,6 +109,9 @@ assert all_cars[0].manufacturer.founded == 1937
Mandatory fields cannot be excluded as it will raise `ValidationError`, to Mandatory fields cannot be excluded as it will raise `ValidationError`, to
exclude a field it has to be nullable. 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. You cannot exclude mandatory model columns - `manufacturer__name` in this example.
```python ```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 Mandatory fields cannot be excluded as it will raise `ValidationError`, to
exclude a field it has to be nullable. 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 !!!tip
Pk column cannot be excluded - it's always auto added even if explicitly Pk column cannot be excluded - it's always auto added even if explicitly
excluded. excluded.