I have a Django model like this:
class MyModel (models.Model):
value = IntegerField()
def custom_field(self):
return self.value + 1
Then in my admin.py file, I have a model:
class MyModelAdmin(admin.ModelAdmin):
list_display = ('id', 'custom_field')
def custom_field(self, obj):
if obj.total_counter_actual != obj.total_counter:
color = 'red'
return format_html(
'<b style="color:{};">{}</b>',
color,
obj.custom_field
)
else:
return obj.custom_field
custom_field.short_description='My custom column name'
Although column name (implying analogue of verbose name) and styling both work as exepcted, instead of values I see something like <bound method MyModel.custom_field of <MyModel: TEST_VALUE>>
. Any way to fix this?