Order a QuerySet by their title, then their name, but keep rows with empty titles last.
Since it's suggested, that Charfields should not be null=True
, you have to convert empty strings to NULL first, to make this work.
from django.db.models import QuerySet, Value
from django.db.models.functions import NullIf
queryset.order_by(
NullIf("title", Value("")).asc(nulls_last=True),
"name"
)