简体   繁体   English

Django模型中的订单查询

[英]Order Query in Django Model

Trying to modify a Django project's filter. 试图修改Django项目的过滤器。

I have the following query 我有以下查询

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

I want to modify this to have the query ordered by 'like_count' 我想修改它以让'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. 如果Like是一个不同的表。

The solution in the below link might help. 以下链接中的解决方案可能会有所帮助。

Django, annotation and ordering using data from other table Django,使用来自其他表的数据进行注释和排序

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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