django - Django - 如何在 if 语句中终止 content_type?
问题描述
我想在我的函数中找出我的内容类型,但无论我如何设计我的 if 语句,我都无法达到“让我”打印语句。我还尝试使用 pprint 来获取 content_type 的命名,但直到现在都没有效果。
def mark_refunded(modeladmin, request, queryset):
queryset.update(status=2)
transactions = queryset.all()
for transaction in queryset.all():
print(transaction)
transaction.sender.acc_usd_balance += float(transaction.amount)
transaction.sender.save()
transaction.receiver.acc_usd_balance -= float(transaction.amount)
transaction.receiver.save()
print(transaction.content_type)
if transaction.content_type == "App | Sell Type A":
print("got me")
似乎我无法将 print(transaction.content_type) 的输出与 if 语句进行比较,为什么呢?我希望输出与我在 if 语句中要求的值相同。
解决方案
假设content_type
是外键,您需要比较if str(...) == ...
.
然而,这里更重要的问题是多个并发请求最终肯定会破坏这些帐户余额,因为您没有以原子方式管理它们。
推荐阅读
- powershell - powershell中的7zip错误的临时文件
- javascript - JavaScript CryptoJS.enc.Base64 等效 C#
- php - 无法访问通过 jquery ajax 发送的 php 文件中的数据
- javascript - 无法在 useEffect 中模拟函数
- php - withCount 与其他属性
- reactjs - Antd Table:如何以编程方式确保行可见?
- git - git clone 后显示为已删除的文件
- sql - 在增量模型上运行时对(无)进行 DBT 过滤
- jmeter - 是否可以在 jmeter 的线程下编写线程?如果是,那么如何?
- javascript - 无法识别由数组动态生成的 div 内调用的事件或方法