[Answered ]-Limiting the number of displayed instances of a model in Django Admin

2👍

You can set the number of items with list_per_page in your ModelAdmin: https://docs.djangoproject.com/en/1.11/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_per_page

The ordering within the admin by default is as defined by in the models options:
https://docs.djangoproject.com/en/1.11/ref/models/options/#ordering.
For custom ordering, you can specify the ordering on your ModelAdmin (see: ModelAdmin.ordering in the docs)

0👍

You have to set the every single Field to be truncated:

e.g i want to truncate field: content

# in model 
from django.template.defaultfilters import truncatechars 

class Article(models.Model):
    """infor for manage every single news"""
    title = models.CharField(max_length=150, default='')
    slug = models.SlugField(max_length=150, null=True)
    description = models.CharField(max_length=255)
    content = models.CharField(max_length=5000)


    @property
    def short_content(self):
    """Use this for truncating content field"""
        return truncatechars(self.content, 200)

so in admin.py

class ArticleAdmin(admin.ModelAdmin):
    fields = ('title', 'description', 'content', 'id_type',)
    list_display = ('id', 'title', 'slug', 'short_content',)

so the field “content will be truncated to less than or equal 200 characters”

Leave a comment