1👍
✅
If you want to translate a model in a straightforward way to a serializer, you can use a ModelSerializer
. You can inject extra parameters to the constructors of the serializer fields with the extra_kwargs
field [drf-doc], so:
class PersonSerializer(serializers.ModelSerializer):
class Meta:
model = Person
fields = ('name',)
extra_kwargs = {
'name': {'required': True}
}
Source:stackexchange.com