umutbozkurt / django-rest-framework-mongoengine

Mongoengine support for Django Rest Framework
MIT License
617 stars 166 forks source link

Exclude from Meta is not working when you use an explicit serializer #244

Open Silviu-Surcica opened 6 years ago

Silviu-Surcica commented 6 years ago
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 6 years ago

@Silviu-Surcica

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.