Django concatenate two querysets for same model

前端 未结 2 793
[愿得一人]
[愿得一人] 2021-01-20 21:28

I have a list of Products, each belonging to a different Distributor.

I need to display a form for each of those products and their corresp

2条回答
  •  盖世英雄少女心
    2021-01-20 21:36

    You can try to do it like here:

    https://stackoverflow.com/a/2176471/4971083

    It's the solution for ordering your records by specific value in Django. You could order your records by distributor_name = 'FirstDistributor'

    p= Product.objects.filter(product__id=product_id).extra(
    select={'is_top': " distributor__name='FirstDistributor'"})
    p = p.extra(order_by = ['-is_top'])
    

提交回复
热议问题