首页 > 解决方案 > 参数如何在 django 中传递

问题描述

我有一个关于如何在 python 中检索theself或 the的简单问题。obj我有这个功能:

def amount_invested_formatted(self, obj):
        value = '$' + intcomma(int(obj.invested))
        return value

    amount_invested_formatted.short_description = "AMOUNT INVESTED" 

和许多其他人一样喜欢它。我这样调用函数list_display

class InvestmentAdmin(ImportExportModelAdmin, admin.ModelAdmin):
    resource_class = InvestmentResource
    list_display = ('amount_invested_formatted',)
    list_display_links = ( 'amount_invested_formatted',)

    def amount_invested_formatted(self, obj):
        value = '$' + intcomma(int(obj.invested))
        return value

    amount_invested_formatted.short_description = "AMOUNT INVESTED" 

它有效,但我不知道在哪里或如何self通过obj。我从这里知道:

admin.ModelAdmin 对象的 list_display 属性指定在更改列表中显示哪些列。该值是被建模对象的属性元组。

但是仍然不清楚什么self或是什么obj,因为从阅读这个,python 函数在参数上很简单,但上面的不是。

那么谁能告诉我这里发生了什么?欣赏答案。

标签: pythondjangofunction

解决方案


推荐阅读