[Python] set priority on Queryset in django

Discussão em 'Python' iniciado por Stack, Março 12, 2025.

  1. Stack

    Stack Membro Participativo

    this is my product and category model:

    class Category(models.Model):
    name = models.CharField(max_length=100)

    class Product(models.Model):
    ...
    category = models.ForeignKey(Category, related_name="products", on_delete=models.CASCADE)


    I want a list of all products with priority order.

    e.g.


    categories_ids = [3,5,1,4,2]
    ​

    now I want data to order like this


    [product_with_category_3, product_with_category_3, product_with_category_3, product_with_category_5, product_with_category_1, product_with_category_1, ...]
    ​

    Continue reading...

Compartilhe esta Página