Home > front end >  How to ordering category items a to z in django admin panel?
How to ordering category items a to z in django admin panel?

Time:02-02

I have a business directory and when i add new company, categories listing mixed style. How can i order categories a to z.

I added my model these meta ordering but didn't worked.

class Category(models.Model):
    name = models.CharField(max_length=100)
    
    class Meta:
        ordering = ['name']

enter image description here

CodePudding user response:

You can write a class in your admin.py file, like the following:

from django.contrib import admin
from .models import Category

class CategoryAdmin(admin.ModelAdmin):
    ordering = ['name']

admin.site.register(Category,CategoryAdmin)
  • Related