It's not possible set the default order to case-insensitive in the model meta options (source).
What you can do is use the order_by method of the QuerySet
of your model:
from django.db.models.functions import Lower
Ingredient.objects.order_by(Lower('name'))
As stated already in this answer
To be able to have it as a default ordering (and avoid repeating the order_by
method on each one of your querysets), you might want to create a custom Manager
class for your Ingredient
model:
# managers.py
from django.db.models.functions import Lower
class OrderedIngredientManager(models.Manager):
def get_queryset(self):
return super().get_queryset().order_by(Lower('name'))
# models.py
from .managers import OrderedIngredientManager
class Ingredient(models.Model):
name = models.CharField(max_length=200,unique=True,null=False)
slug = models.SlugField(unique=True)
ordered_objects = OrderedIngredientManager()
So you can have all your QuerySet
ordered:
Ingredient.ordered_objects.all()