Two filters on two tables using prefetch_related
<p>Let's suppose this is my model:</p>

<pre><code>class Pizza(models.Model):
    size = models.IntegerField()
    #other fields

class Order(models.Model):
    date = models.DateField()
    pizza = models.ManyToManyField(Pizza, through='OrderPizza')
    #other fields


class OrderPizza(models.Model):
    update = models.BooleanField()
    order = models.ForeignKey(Order, on_delete=models.CASCADE)
    pizza = models.ForeignKey(Pizza, on_delete=models.CASCADE)
</code></pre>

<p>I try to see within the last order the id of the pizza with size 32. <strong>How can I do that using only one queryset?</strong> </p>

<pre><code>#I take the last order:
last_order =  Orders.objects.filter().order_by('-order_number')[:1]

#If we have at least one order
if last_order:
    var_last_order_id = last_order[0].id
    #First filter
    queryset_orders = Orders.objects.filter(id=var_last_order_id).prefetch_related('pizza')

    for food in queryset_orders:
        #Second filter
        pizza32 = food.pizza.filter(size = 32)
        print pizza32.id
</code></pre>