سؤال

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