Exclude from Meta is not working when you use an explicit serializer
Silviu-Surcica opened this issue · 1 comments
Silviu-Surcica commented
class Item(Document):
name = StringField(max_length=255, required=False)
units = ListField(ReferenceField(Unit))
class BasicUnitSerializer(DocumentSerializer):
class Meta:
model = Unit
fields = ('unit_id', 'name', )
depth = 1
verbose = 'unit'
verbose_plural = 'units'
class ItemSerializer(DocumentSerializer):
units = BasicUnitSerializer(many=True, required=False)
class Meta:
model = Item
exclude = ('units', )
verbose_plural = 'items'
depth = 1
If I use BasicUnitSerializer for units, the exclude does not work. But if I let units be serialized by a default NestedSerializer, then the exclude works.
BurkovBA commented
Hi, thanks for reporting an issue!
Yep, fields
and exclude
attributes of Meta
don't take into account explicitly declared fields.
I'll check if that's inconsistent with pure DRF, and if so, will create tests and fix this.