# ChangeList.\_get\_deterministic\_ordering() and UniqueConstraint

**URL:** <https://forum.djangoproject.com/t/changelist-get-deterministic-ordering-and-uniqueconstraint/898>\
**Category:** Django Internals\
**Created:** [January 20, 2020, 10:17am UTC](https://forum.djangoproject.com/t/changelist-get-deterministic-ordering-and-uniqueconstraint/898 "2020-01-20T10:17:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sanjioh](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/sanjioh/32/2992_2.png) [@sanjioh](https://forum.djangoproject.com/u/sanjioh)\
**Post date:** [January 20, 2020, 10:17am UTC](https://forum.djangoproject.com/t/changelist-get-deterministic-ordering-and-uniqueconstraint/898/1 "2020-01-20T10:17:20Z")

</div>

Hello everyone,

I’ve been fiddling with db indexes lately to improve the performance of an admin view.  
Eventually I found this PR [https://github.com/django/django/pull/10692](https://github.com/django/django/pull/10692) which ensures the records displayed by `ChangeList` are deterministically ordered.  
Among other things, the code looks for the presence of a `unique_together` attribute on the `Meta` class of the model to determine if the model is already totally ordered.

I was wondering if `_get_deterministic_ordering()` should check for the presence of `UniqueConstraint`s as well, which currently aren’t considered by the discovery algorithm.  
I noticed the docs currently advise against using `unique_together` in favor of `UniqueConstraint`, suggesting the former may be deprecated in the future, which was the reason that prompted me to make this post 🙂

What do you think?

Thanks,

Fabio

---

<div class="post-metadata">

**Author:** ![adamchainz](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/adamchainz/32/26_2.png) [@adamchainz](https://forum.djangoproject.com/u/adamchainz)\
**Post date:** [January 20, 2020, 10:49am UTC](https://forum.djangoproject.com/t/changelist-get-deterministic-ordering-and-uniqueconstraint/898/2 "2020-01-20T10:49:05Z")

</div>

Yes that sounds like a legitimate improvement to me!

Please follow the contributing guide to open this as a ticket, and work on a PR if you want!  
[https://docs.djangoproject.com/en/dev/internals/contributing/](https://docs.djangoproject.com/en/dev/internals/contributing/)

---

<div class="post-metadata">

**Author:** ![sanjioh](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/sanjioh/32/2992_2.png) [@sanjioh](https://forum.djangoproject.com/u/sanjioh)\
**Post date:** [January 20, 2020, 4:27pm UTC](https://forum.djangoproject.com/t/changelist-get-deterministic-ordering-and-uniqueconstraint/898/3 "2020-01-20T16:27:42Z")

</div>

Thank you @adamchainz,

I’ll go ahead and file a ticket. I’m willing to work on a PR as well.

EDIT: related ticket at [https://code.djangoproject.com/ticket/31187](https://code.djangoproject.com/ticket/31187)

---

<div class="post-metadata">

**Author:** ![sanjioh](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/sanjioh/32/2992_2.png) [@sanjioh](https://forum.djangoproject.com/u/sanjioh)\
**Post date:** [January 24, 2020, 10:08am UTC](https://forum.djangoproject.com/t/changelist-get-deterministic-ordering-and-uniqueconstraint/898/4 "2020-01-24T10:08:54Z")

</div>

If anybody’s interested, here is the related PR [https://github.com/django/django/pull/12364](https://github.com/django/django/pull/12364)
