Django - 如何在 if 语句中终止 content_type?

Django - How to tertermine content_type in if statement?

我想知道 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(...) == ....

然而,这里更重要的问题是多个并发请求最终肯定会破坏这些帐户余额,因为您没有以原子方式管理它们。