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']
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)