It seems like Django by default adds ORDER BY
to queries. Can I clear it?
from slowstagram.models import InstagramMedia
print InstagramMedia.objects.filter().query
SELECT
`slowstagram_instagrammedia`.`id`,
`slowstagram_instagrammedia`.`user_id`,
`slowstagram_instagrammedia`.`image_url`,
`slowstagram_instagrammedia`.`video_url`,
`slowstagram_instagrammedia`.`created_time`,
`slowstagram_instagrammedia`.`caption`,
`slowstagram_instagrammedia`.`filter`,
`slowstagram_instagrammedia`.`link`,
`slowstagram_instagrammedia`.`attribution_id`,
`slowstagram_instagrammedia`.`likes_count`,
`slowstagram_instagrammedia`.`type`
FROM
`slowstagram_instagrammedia`
ORDER BY
`slowstagram_instagrammedia`.`id`
ASC
```
Actually, just do a
query.order_by()
is enough.Here is the implementation of
order_by
, for your reference -You can use:
clear_ordering
method from queryExample:
Try to use
.order_by('?')
at the end of queryset.