Charfield case insensitive sorting in Model Admin

52 views
Skip to first unread message

Azam Alias

unread,
Oct 29, 2014, 2:21:29 AM10/29/14
to django...@googlegroups.com
Hi,

I am using Django 1.7 on Python 3.4 and quite new to both Django and Python.

I would like to sort a name field (Charfield) in ModelAdmin view in case-insensitive way. The default sorting is case-sensitive.

How could I sort it in case-insensitive?

Thanks in advance.

Collin Anderson

unread,
Oct 29, 2014, 2:39:53 PM10/29/14
to django...@googlegroups.com
Hello,

One way to do it would be to have add an editable=False field name_sort that's a lower() version of your name field. You can update that field in the save method.

In the admin, you can tell it to order by name_sort using admin_order_field.

Collin

Azam Alias

unread,
Oct 31, 2014, 8:38:01 PM10/31/14
to django...@googlegroups.com
Hi Collin,

Thanks for the solution !
Reply all
Reply to author
Forward
0 new messages