If I'm understanding you correctly, you could use a callable in the 
list_display definition.
https://docs.djangoproject.com/en/2.0/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_display

def lower_case_name(obj):
    return ("%s" % str(obj).lower()
lower_case_name.short_description = 'Substance'

class SubstanceAdmin(admin.ModelAdmin):
    list_display = (lower_case_name,)

-----Original Message-----
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Mike Dewhirst
Sent: Wednesday, January 10, 2018 1:03 AM
To: Django users
Subject: Admin case-insensitive sorting question

I have tried every which way to produce a case-insenstive list of substances in 
the Admin including this:

def get_queryset(self, request):
     return super(SubstanceAdmin,
self).get_queryset(request).order_by(Lower('name').asc())

Which DOES work (as proven via print statement) but doesn't display that way in 
the Admin which uses the natural ascii order. It is the list_display feature 
which re-orders the substances.

I can get them sorting pseudo-insensitively by using a method to uppercase the 
first char of the name and passing that method to list_display.

However, that prevents the column order reversal feature which is a function of 
the list_display feature.

I thought a case insensitive model manager might work until I saw in the docs 
that subsequent order_by filtering will spoil it and I would still have to 
pseudo_name them anyway.

So the question is ... should I bite the bullet and add a sort field to the 
model and fill it with the substance name converted to lower-case?

Thanks

Mike

--
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b1fc1d23-b0ab-d35e-9049-9a4f6091a4f7%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/205b80f44a9f47569f5715825dc2c106%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.

Reply via email to