from rest_framework import serializers
from .models import Stock
class StockSerializer(serializers.ModelSerializer):
class Meta:
model = Stock
#field = ('ticker','volume')
field = '__all__'
I am getting an exception value on running application : ("Creating a ModelSerializer without either the 'fields' attribute or the 'exclude' attribute has been deprecated since 3.3.0, and is now disallowed. Add an explicit fields = '__all__' to the StockSerializer serializer.",)
As the error message says, the required attribute is fields
with an 's', not field
.
I assume that your serializer currently looks like:
class StockerSerializer(serializers.Serializer):
class Meta:
model = Stock
The issue Django is complaining about is that the meta class needs to define which fields in the Stock model it needs to serialize. You have three options: you can either put fields = (‘some’, ‘fields’,...)
, exclude = (‘fields’, ‘other’, ‘than’, ‘these’...)
, or fields = ‘__all__’
.
The easiest option is the last one and it will cause the serializer to serialize all the fields in the Stock model which is probably what you want. You should then revise your code to look like:
class StockerSerializer(serializers.Serializer):
class Meta:
model = Stock
fields = ‘__all__’
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With