我试图通过外键中的用户名字段按字母顺序排序,如此
friends = Friend.objects.filter(recipient=user, status=1).order_by('owner__username') | Friend.objects.filter(owner=user, status=1).order_by('recipient__username')
答案 0 :(得分:0)
friends = Friend.objects.filter(Q(owner=user, status=1) | Q(recipient=user, status=1)).order_by('owner__username', 'recipient__username')