[Fixed]-How can I filter instances of a model in django, with a queryset value of filter field?

1👍

Nothing magic

ModelA.objects.filter(att1=queryset of modelB)

0👍

say you have object B with fields att2 and att3

class modelA(models.Model):
    att1 = models.ForeignKey(modelB)


class modelB(models.Model):
   att2 = models.CharField(max_length=255)
   att3 = models.CharField(max_length=255)

then you filter by doing:
results = modelA.objects.filter(att1__att2=’foo’)

hope this helps

Leave a comment