Skip to content

Commit 1b86d15

Browse files
committed
Use methode(self, obj) in InlineModelAdmin for use in readonly_fields. see https://docs.djangoproject.com/en/1.6/ref/contrib/admin/#django.contrib.admin.ModelAdmin.readonly_fields
""" A read-only field can not only display data from a model’s field, it can also display the output of a model’s method or a method of the ModelAdmin class itself. """
1 parent c99a629 commit 1b86d15

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

xadmin/plugins/inline.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,9 @@ def instance_form(self, **kwargs):
226226
elif inspect.ismethod(getattr(inst, readonly_field, None)):
227227
value = getattr(inst, readonly_field)()
228228
label = getattr(getattr(inst, readonly_field), 'short_description', readonly_field)
229+
elif inspect.ismethod(getattr(self, readonly_field, None)):
230+
value = getattr(self, readonly_field)(inst)
231+
label = getattr(getattr(self, readonly_field), 'short_description', readonly_field)
229232
if value:
230233
form.readonly_fields.append({'label': label, 'contents': value})
231234
return instance

0 commit comments

Comments
 (0)