[Django]-Make django admin to display no more than 100 characters in list results

58👍

You can display a property that returns a truncated version of your field’s value in your ModelAdmin class. Leveraging the built-in template filters makes this easy.

from django.template.defaultfilters import truncatechars  # or truncatewords

class Foo(models.Model):
    description = models.TextField()

    @property
    def short_description(self):
        return truncatechars(self.description, 100)

class FooAdmin(admin.ModelAdmin):
    list_display = ['short_description']

3👍

In Your Admin.py File :

class ApplicationAdmin(admin.ModelAdmin):
    list_display = ['titl1','title2'] # titl1 is behalf of title1
    
    def titl1(self, obj):
        return obj.title1[:100]

Leave a comment