Reputation: 4008
I want in Django admin to truncate the number of characters for a field.
For example, for:
list_display = ('description')
I want to show only the first 20 characters.
Upvotes: 1
Views: 938
Reputation: 631
You can do that:
In your model or admin class, define a method like this:
def get_description(self):
return self.description [:20]
get_description.short_description="Description"
And in your admin class:
list_display='get_description',
Upvotes: 1
Reputation: 631
You can define a method to do that for example:
def get_description(self):
return self.description [:20]
get_description.short_description = "Description"
And you define list_display=('get_description')
Upvotes: 2