I want to display a form in the list_display in django admin, but I\'m facing this problem:
when I define something like this:
class MyModelAdmin(adm
Here's what appears in the documentation. Few hints:
I think you should include pagar_pase
in your list_display
tuple and also you are better off using format_html
than the triple quotes.
from django.utils.html import format_html
class Person(models.Model):
first_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
color_code = models.CharField(max_length=6)
def colored_name(self):
return format_html('{1} {2}',
self.color_code,
self.first_name,
self.last_name)
colored_name.allow_tags = True
class PersonAdmin(admin.ModelAdmin):
list_display = ('first_name', 'last_name', 'colored_name')
Here, they define first the model and then create a ModelAdmin
and there, they include the method's name in the list_display
which you're missing.
Your code should be like this:
class MyModelAdmin(admin.ModelAdmin):
list_display = ('foo', 'my_custom_display', 'pagar_pase')
def pagar_pase(self, obj):
# I like more format_html here.
return """ """
pagar_pase.description = 'Testing form output'
pagar_pase.allow_tags = True
Hope it helps!