I have two queryset, and need the product (aka "CROSS JOIN").
I could use this:
itertools.product(queryset_a, queryset_b)
BUT the result is too big, and I need to paginate it.
This means, I need to avoid itertools.product()
and use the Django ORM to create the product in the database.
How to do itertools.product(queryset_a, queryset_b)
via Django ORM?
I use PostgreSQL.
Example of what I mean with "product":
itertools.product(['a', 'b', 'c'], [1, 2, 3])
[('a', 1), ('a', 2), ('a', 3),
('b', 1), ('b', 2), ('b', 3),
('c', 1), ('c', 2), ('c', 3)]
The resulting Queryset needs to support .count()
since I want to paginate it.
class Term(models.Model):
name = models.CharField(max_length=1024)
class Location(models.Model):
name = models.CharField(max_length=1024)