1👍
Your best bet might be to use a through model. If you don’t want to do that, I’d try out something like this:
categories = Rack.objects.get(number=1).categories.all().values_list('name', flat=True)
Product.objects.filter(categories__name__in=categories)
Also, do you mean for this:
class Product(models.Model):
...
Category = models.ManyToManyField(Category)
to be:
class Product(models.Model):
...
categories = models.ManyToManyField(Category)
like in your Rack
model?
Source:stackexchange.com