Hi all,
I have a situation here where I do not know how to use
the filter() function in the database API to obtain a
QuerySet. I am describing the schema and what I have
done, below. I hope you have an answer to my question.
# Only the necessary fields are shown here
class A(models.Model):
p
How about just making the query like this:
A.objects.filter(b__status=1)
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To u
SmileyChris wrote:
> How about just making the query like this:
>
> A.objects.filter(b__status=1)
This returns the list of rows in table A that have status
in table B set to 1 at some point in the past. What I want
is the latest status from table B. For example, if table B
has the two entries:
Suriya,
You will probably have to do this in custom SQL or using extra(). Your
query requires a subselect to get the "current B's" (B's with max(date)
for each A).
Here's the SQL that I think you need (if I understand the problem
correctly):
select * from _A join _B on _B.a_id = _A.id
where _B.
Suriya wrote:
> This returns the list of rows in table A that have status
> in table B set to 1 at some point in the past. What I want
> is the latest status from table B.
I see. Yes, you can either use a (grouping) custom SQL query or
refactor.
How I would do it is to have just one model (B)
DavidA wrote:
> Suriya,
>
> You will probably have to do this in custom SQL or using extra(). Your
> query requires a subselect to get the "current B's" (B's with max(date)
> for each A).
>
> Here's the SQL that I think you need (if I understand the problem
> correctly):
>
> select * from _A join
6 matches
Mail list logo