Django - Create the equivalent of a “cross-join” q

2019-09-16 05:48发布

I have two Django models with are related to each other through a many-to-many relationship.

I need to list the cross product of both tables.

Let say for simplicity's sake that the two models are Pizza and Topping.

I would like the query to return something like this:

pizza_name    topping
---------------------
all dressed   cheese
all dressed   mushrooms
all dressed   onions
all dressed   peperoni
all dressed   pepper
reddit        cheese
reddit        peperoni
reddit        bacon
reddit        baconbits

The amount of data will be very large and I absolutely need to use count and slices so I can't simply iterate a model and treat the data as I go along.

Any idea how I should proceed?

1条回答
▲ chillily
2楼-- · 2019-09-16 06:27

I eventually solved it by simply iterating on the intermediate table.

查看更多
登录 后发表回答