myapp/admin.py from django.contrib import admin from django.utils.text import Truncator from django.db import models from .models import Product def truncated_name(obj): name = "%s" % obj.name return Truncator(name).chars(70) class ProductAdmin(admin.ModelAdmin): list_display = ['id', truncated_name, 'category', 'timestamp',] list_display_links = [truncated_name] list_filter = ['category'] class Meta: model = Product
You can also override these fields:
formfield_overrides = { models.CharField: {'widget': TextInput(attrs={'size': '20'})}, models.TextField: {'widget': Textarea(attrs={'rows': 1, 'cols': 40, 'style': 'height: 1.5em;'})}, }
source share