django serializer fields code example
Example 1: how to set required drf serialzier
class MySerializer(serializer.Modelserializer):
class Meta:
model = MyModel
fields = ['id', 'title']
extra_kwargs = {
"title": {"required": False}
}
Example 2: serializers.py include all fields
# Include all fields in the Order model in the Serializer
class OrderSerializer(serializers.ModelSerializer):
class Meta:
model = Order
fields = '__all__'