I have these data models in django:
class User(models.Model):
type = models.CharField()
class Tmp1(models.Model):
var1 = models.ForeignKey(User)
class Tmp2(models.Model):
var2 = models.ForeignKey(Tmp1)
class Tmp3(models.Model):
user = models.ForeignKey(User)
var3 = models.ForeignKey(Tmp2)
I want to have a Tmp3 queryset which selects instances of Tmp3 which Tmp3.var3.var2.var1.id equals Tmp3.user.id.
I know how I should do it with InnerJoin in PostgreSQL but I don’t know how to do it with Django queryset.
From what I understand you want to get
Tmp3objects in which theiruserattribute matches the related user in theTmp1table (for the currentTmp3object) – it sounds like you can make use of F expressions