我有一个返回queryset
的函数,但现在我想对queryset
进行排序,但我不确定如何做到这一点。
def get_queryset(self):
print('--------------------------------')
# print(self.request.basket.all_lines()[0].product.upc)
print('--------------------------------')
return self.request.basket.all_lines()
self.request.basket.all_lines()
会返回一个查询集,但我想按产品的 upc 对其进行排序
我可以通过print(self.request.basket.all_lines()[0].product.upc)
获取upc
我确定 .product.upc
确实存在并且我的方向是正确的。
有人可以帮我吗?
最佳答案
你试过这个吗?
return self.request.basket.all_lines().order_by('product__upc')
关于python - 如何按属性的属性对查询集进行排序? Django ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42476581/