简体   繁体   中英

Order Query in Django Model

Trying to modify a Django project's filter.

I have the following query

queryset = Post.objects.filter(public=True)

I want to modify this to have the query ordered by 'like_count'

How would I implement this?

通过使用order_by ,像这样:

q = Post.objects.filter(public=True).order_by('like_count')

If Like is a different table.

The solution in the below link might help.

Django, annotation and ordering using data from other table

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM