I have worked with joins with django and I'm kind of used to them, however, they normally require you to use filters that use an external value. What is the simplest way to get a filter that only requires joining two models and no external value?
For instance:
Code:
class Model1(models.Model):
name = models.CharField(max_length=255)
class Model2(models.Model):
parent = models.ForeignKey(Model1)
name = models.CharField(max_length=255)
As an example of a query requiring an external value, suppose I'd like to get the Model1 instances that are related to instances of Model2 whose names are 'Foo':
Code:
r = Model1.object.filter(model2__name='Foo')
Good.... but how about if I want to get the instances of Model1 that are related to at least a single instance of a Model2?
Code:
r = Model1.object.filter(pk=model2__parent)
I'm trying something like that, but it doesn't work.