You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Django provides the .defer() optimization for querysets. This optimization drops the deferred field from the SQL query sent to the database. That is, Country.objects.first().defer('states') means "don't even ask the database for the country's states field."
drf-flex-fields's documentation reads:
Alternatively, you could treat country as a "deferred" field by not defining it among the default fields. To make a field deferred, only define it within the serializer's expandable_fields.
When drf-flex-fields is used to "defer" a field in this way, is Django's .defer() actually used under the hood?
Asked another way: will the default response for the below serializer retrieve a country's states field from the database or not?
class CountrySerializer(FlexFieldsModelSerializer):
class Meta:
model = Country
fields = ['name', 'population']
expandable_fields = {
'states': (StateSerializer, {'many': True})
}
The text was updated successfully, but these errors were encountered:
Django provides the
.defer()
optimization for querysets. This optimization drops the deferred field from the SQL query sent to the database. That is,Country.objects.first().defer('states')
means "don't even ask the database for the country'sstates
field."drf-flex-fields's documentation reads:
When drf-flex-fields is used to "defer" a field in this way, is Django's
.defer()
actually used under the hood?Asked another way: will the default response for the below serializer retrieve a country's
states
field from the database or not?The text was updated successfully, but these errors were encountered: