python - 参数如何在 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 函数在参数上很简单,但上面的不是。
那么谁能告诉我这里发生了什么?欣赏答案。
解决方案
推荐阅读
- python - 关键词分类模型
- ruby-on-rails - Webpacker(或 Webpack)environment.js 与 application.js
- java - 使用 MVP 对 Kotlin 进行改造的 Api 调用问题
- material-ui - 将 id 添加到 Tab 字段 @material-ui/core
- database - 用于数据复制、资源和性能的 oracle 数据库链接
- java - 使用spring boot无法防止spring security中同一用户的多个并发登录
- c# - 获取大量随机数的最快方法
- linux - 在linux系统中找不到安装程序命令
- android - 无法理解的 Stacktrace 崩溃
- angularjs - 如何在 angularJs ng-disabled 中使用自定义指令?