[Fixed]-How do I query objects of a ManyToManyField?(without through)


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)

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?

Leave a comment