Domanda

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

È stato utile?

Soluzione 2

I used

{% for i in img %} 

instead of

{% while i=img.0 %} 

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

Altri suggerimenti

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 ?

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top