How can I filter data from a table with a Foreign Key?
<p>I have the following models:</p>

<pre><code>#- coding: utf-8 -#

STATUSES = (
    (u'R', u'Solicitada'),           # Request
    (u'V', u'Válida'),               # Deposit
    (u'P', u'Imprimiendo'),          # Printing
    (u'S', u'Por Entregar'),         # Stock
    (u'D', u'Entregada'),            # Delivered
    (u'F', u'Olvidadas')             # Forget
)

class Order(models.Model):
    requester = models.CharField(max_length=128)

class OrderStatus(models.Model):
    order = models.ForeignKey(Order, related_name="statuses")
    status = models.CharField(max_length=1,choices=STATUSES)
    date = models.DateTimeField()
</code></pre>

<p>I need to filter the Orders by status and by date. I've tried the following:</p>

<pre><code>orders_sold = Order.objects.all()
orders_sold = orders_sold.filter(statuses__status='V')
</code></pre>

<p>But it returns whatever it wants, and with the date, I've tried:</p>

<pre><code>orders_sold = orders_sold.filter(statuses__date__range=[from_date,to_date])
</code></pre>

<p>But it says that "date" doesn't exists.</p>

<p>How can I achieve what I'm looking to do?</p>

<p>UPDATE</p>

<p>The error that "date" gives is this:</p>

<pre><code>Cannot resolve keyword 'date' into field. Choices are: added, additionalinfoorder, email, id, orderitems, password, payment, payment_date, payments, phone, print_orders, requester, statuses, taker, viewed
</code></pre>