I used
{% for i in img %}
instead of
{% while i=img.0 %}
in my template, and the results show no duplicates now.
Вопрос
When i run this query:
img = sit_img.objects.filter(cardinality=0).order_by('?').distinct('idImage')[:5]
I recieve a transaction error. The problem comes only when i combine order_by() and distinct() in a query. If this is a bug, there's another aproach using Django ORM?
Решение 2
I used
{% for i in img %}
instead of
{% while i=img.0 %}
in my template, and the results show no duplicates now.
Другие советы
4 Documentation.
When you specify field names, you must provide an order_by() in the QuerySet, and the fields in order_by() must start with the fields in distinct(), in the same order.
Might be the case with you ?