4👍
Just make a copy of serializer_field_mapping
from the base class of your serializer and update it with new “model field – serializer” field pair. For example if you use ModelSerializer
subclass then:
from rest_framework import serializers
class MySerializer(serializers.ModelSerializer):
serializer_field_mapping = (
serializers.ModelSerializer.serializer_field_mapping.copy()
)
serializer_field_mapping[models.BinaryField] = MyBinaryField
0👍
One way to do this,
class MySerializer(serializers.Serializer):
logo = MyBinaryField()
However, I suppose you are asking about overriding model serializer field then you could use the following,
class AccountSerializer(serializers.ModelSerializer):
logo = MyBinaryField(read_only=True)
class Meta:
model = Account
- [Django]-Python what does self[name] = value means?
- [Django]-Django: composite fields or embedded classes (like JPA)?
- [Django]-How can I fix PostgreSQL canceling statement error on Google SQL?
- [Django]-Another Cannot set values on a ManyToManyField which specifies an intermediary model
Source:stackexchange.com