in my mongo model definitions I added a new field with a default value
class Component(Document):
title = StringField(null=True)
new_field = StringField(default="THE_DEFAULT_VALUE")
My serializer
from rest_framework_mongoengine.serializers import DocumentSerializer
class MySerializers(DocumentSerializer):
class Meta:
model = Component
fields = ['id', 'title', 'new_field']
The response, in this case, will contain the filed new_field with the value THE_DEFAULT_VALUE in all of the returned objects even though this new_field is not in any of the documents yet
Is this is the default behavior or I'm missing something? because it makes much more sense that we don't return values that are not in the DB unless it was explicitly defined in the serializer to do that.
Do you mean that you created some Component documents in the database with new_field field missing, but the serializer still returns JSONs with "new_field = "THE DEFAULT VALUE"" as if it were there?
Hi
I'm using
And noticed a strange behavior:
My serializer
The response, in this case, will contain the filed
new_field
with the valueTHE_DEFAULT_VALUE
in all of the returned objects even though thisnew_field
is not in any of the documents yetIs this is the default behavior or I'm missing something? because it makes much more sense that we don't return values that are not in the DB unless it was explicitly defined in the serializer to do that.