Django get related objects ManyToMany relationships
<p>i have two models:</p>

<pre><code>class CartToys(models.Model):
    name = models.CharField(max_length=350)
    quantity = models.IntegerField()

class Cart(models.Model):
    cart_item = models.ManyToManyField(CartToys)
</code></pre>

<p>i want to get all related toys to this cart. how can i do this </p>

<p>you would use...</p>

<pre><code>cart = Cart.objects.first()
objects = cart.cart_item.all() # this line return all related objects for CartToys
# and in reverse
cart_toy = CartToys.objects.first()
carts = cart_toy.cart_set.all() # this line return all related objects for Cart
</code></pre>

python django