dsimond
dsimond

Reputation: 113

How to filter a query on the results of another one in django?

Lets say that i have 2 models :

Class OrderEvent(models.Model):
    isPaid = models.Booleanfield()


Class Participant(models.Model):
    orderEvent = models.ForeignKey(OrderEvent)
    participantFirstName = models.CharField()
    participantLastName = models.CharField()
    #etc...

And i want to get all the participants where Orderevent.isPaid = True.

I think that i struggle to do something very simple...

Upvotes: 0

Views: 89

Answers (1)

Süleyman Can
Süleyman Can

Reputation: 363

It is very simple;

Participant.objects.filter(orderEvent__isPaid=True)

As a suggestion you can follow,

naming conventions from here.

Django making queries from here.

Upvotes: 3

Related Questions