from django.db import models
class School(models.Model):
name = models.CharField(max_length=255)
county = models.CharField(max_length=255)
class Meta:
ordering = ("name",)
$ python manage.py shell
...
>>> from testapp.models import School
>>> str(School.objects.values("county").distinct().query)
'SELECT DISTINCT "testapp_school"."county", "testapp_school"."name" FROM "testapp_school" ORDER BY "testapp_school"."name" ASC'
>>> str(School.objects.values("county").order_by().distinct().query)
'SELECT DISTINCT "testapp_school"."county" FROM "testapp_school"'
Tobias McNulty
Chief Executive Officer
--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CAMGFDKRQsbUz%3DeYKxX2U%2B892AgQbXr%3DMA9AiWw9vfiPcM%2BnAXw%40mail.gmail.com.
I’d vote for option 2. I don’t think it can be expected the ordering will be obeyed when not selecting the columns it includes.
>>> str(School.objects.values("county").order_by("name").distinct().query)
On 28.10.2020., at 20:04, Tobias McNulty <tob...@caktusgroup.com> wrote:
--
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/942B7E2C-7B44-4ECF-9105-6EAB90874E98%40gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/691662a4-9ad4-44a7-b2d2-1ecd0d95c30fn%40googlegroups.com.