class AccountSerializer(serializers.ModelSerializer):
class Meta:
model = Account
fields = ['id', 'account_name', 'users', 'created']
models.py
=========
class Order(models.Model):
...
def tax_status(self, check_item_bought=True):
...
serializers.py
==========
class YourSerializer(serializers.ModelSerializer):
tax_status = serializers.CharField(required=False)
tax_status_all = serializers.SerializerMethodField()
class Meta:
model = Order
fields = ("tax_status", "tax_status_all")
def get_tax_status_all(self, obj): # "get_" + field name
return obj.tax_status(check_item_bought=False)
serializer = CommentSerializer(data={'email': 'foobar', 'content': 'baz'})
serializer.is_valid()
# False
serializer.errors
# {'email': ['Enter a valid e-mail address.'], 'created': ['This field is required.']}