使用Django 1.1:在Django ModelAdmin對象上使用任意方法或屬性作爲字段?
Django admin docs describe在類屬性list_display
中的ModelAdmin對象上使用任意方法或屬性。這是在模型的列表顯示中顯示任意信息的很好的機制。但是,對於更改頁面本身,似乎沒有類似的機制。 什麼是最簡單的方法來完成這個有用的小功能,以顯示ModelAdmin更改表單頁面上的任意非字段派生信息?
所需設置的一個具體的例子:
class CustomUserAdmin(UserAdmin):
def registration_key(self, obj):
"""Special method for looking up and returning the user's registration key
"""
return 'the_key'
list_display = ('email', 'first_name', 'last_name', 'is_active', 'is_staff',
'registration_key') # <- this works
fields = ('email', 'first_name', 'last_name', 'is_active', 'is_staff',
'registration_key') # <- this DOESN'T work?
我希望! 'readonly_fields'在Django 1.2中是新的,現在我被困在1.1中。 – 2010-08-25 20:12:16
那你真是太幸運了,恐怕 - 在沒有嚴重黑客入侵的情況下,1.1中沒有辦法做到這一點。 – 2010-08-28 11:31:42