Django-如何在if语句中定义输入的内容?

Django-如何在if语句中定义输入的内容?,django,content-type,Django,Content Type,我想知道我函数中的内容类型,但无论我如何设计if语句,我都无法获得“get me”打印语句。我还尝试使用pprint来获得content_类型的命名,但到目前为止没有任何效果 def mark_refunded(modeladmin, request, queryset): queryset.update(status=2) transactions = queryset.all() for transaction in queryset.all(): p

我想知道我函数中的内容类型,但无论我如何设计if语句,我都无法获得“get me”打印语句。我还尝试使用pprint来获得content_类型的命名,但到目前为止没有任何效果

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\u type
是外键,则需要比较
if str(…)==…


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

是的,这就成功了,我自己可能永远也不会明白,谢谢!