sunprophit
sunprophit

Reputation: 1699

Django query with join?

I have two models:

class Contact(models.Model):
    name = models.CharField(max_length=255)

class Campaign(models.Model):
    contact = models.ForeignKey(Contact, related_name="campaigns")
    name = models.CharField(max_length=255)

How can I select all contacts that have campaign name='CampaignName' in Campaign table?

Upvotes: 0

Views: 78

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 600051

Contact.objects.filter(campaign__name='CampaignName')

Upvotes: 1

Related Questions