我在mongoengine中有一个十进制字段,我试图返回存储在模型中的数据,但是当我尝试返回对象时,我在编码中收到错误
TypeError: Object of type 'Decimal' is not JSON serializable
class PaymentTransactionSchema(Document):
meta = {
'collection': 'payment_transaction'
}
payment_mode = StringField()
payment_reference_code = StringField()
currency = StringField()
amount = DecimalField()
status = StringField()
approval_code = StringField()
remarks = StringField()
createdate = DateTimeField(default=datetime.datetime.utcnow)
class ProjectFundTransaction(ModelSchema):
class Meta:
model = ProjectFundTransactionSchema
然后像这样的回报
self.__transaction = PaymentTransactionSchema(**args)
res = self.__transaction.save()
transaction = self.dump(res).data
我希望棉花糖能够自动处理此问题,但似乎我错过了某个地方的配置