[Answered ]-Django models distinct is still returning duplicates

1👍

Your phone_number field is an EncryptedCharField, I assume you use this package: django-cryptographic-fields. As it states in it’s repositories readme file:

Due to the nature of the encrypted data, filtering by values contained
in encrypted fields won’t work properly. Sorting is also not
supported.

This is the reason your distinct or even the ordering doesn’t work (['9711231234', '5095551212', '9994441212', '9994441212', '9711231234'] is not ordered). In general encrypting something and expecting to make such filters, etc. on them doesn’t make much sense, if you really want to do this kinds of thing switch to a normal CharField.

Leave a comment