Serializers¶
Serializers for various types of mongoengine documents. Replace of DRF ModelSerializer
. Usage is the same.
DocumentSerializer¶
-
class
rest_framework_mongoengine.serializers.
DocumentSerializer
(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)¶ Bases:
rest_framework.serializers.ModelSerializer
Serializer for Documents.
Recognized primitve fields:
StringField
URLField
EmailField
IntField
LongField
FloatField
DecimalField
BooleanField
DateTimeField
ComplexDateTimeField
ObjectIdField
SequenceField
(assumes it has integer counter)UUIDField
GeoPointField
GeoJsonBaseField
(all those fields)
Compound fields:
ListField
andDictField
are mapped to corresponding DRF fields, with respect to nested field specification.The
ReferenceField
is handled likeForeignKey
in DRF: there nested serializer autogenerated if serializer depth greater then 0, otherwise it’s handled by it’s own (results asstr(id)
).For
EmbeddedDocumentField
also nested serializer autogenerated for non-zero depth, otherwise it is skipped. TODO: THIS IS PROBABLY WRONG AND SHOULD BE FIXED.Generic fields
GenericReferenceField
andGenericEmbeddedDocumentField
are handled by their own with corresponding serializer fields.Not well supported or untested:
FileField
ImageField
BinaryField
All other fields are mapped to
DocumentField
and probably will work wrong.
EmbeddedDocumentSerializer¶
-
class
rest_framework_mongoengine.serializers.
EmbeddedDocumentSerializer
(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)¶ Bases:
rest_framework_mongoengine.serializers.DocumentSerializer
Serializer for EmbeddedDocuments.
Skips id field and uniqueness validation.
DynamicDocumentSerializer¶
-
class
rest_framework_mongoengine.serializers.
DynamicDocumentSerializer
(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)¶ Bases:
rest_framework_mongoengine.serializers.DocumentSerializer
Serializer for DynamicDocuments.
Maps all undefined fields to
fields.DynamicField
.