DRF -Modellmethoden Serializer
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)
astarrh