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?

I founded people having the same error

有帮助吗?

解决方案 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 ?

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top