Question

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

Was it helpful?

Solution 2

I used

{% for i in img %} 

instead of

{% while i=img.0 %} 

in my template, and the results show no duplicates now.

OTHER TIPS

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 ?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top