How do you join two tables on a foreign key field using django ORM?

前端 未结 4 1865
天命终不由人
天命终不由人 2020-12-04 21:54

Let\'s assume I have the following models:

class Position(models.Model):
    name = models.CharField()

class PositionStats(models.Model):
    position = mod         


        
4条回答
  •  -上瘾入骨i
    2020-12-04 22:52

    From django.db import connection In your view include the below statement:

    cursor = connection.cursor()
    cursor.execute("select * From Postion ON Position.name = Player.position JOIN
    PlayerStats ON Player.name = 
    PlayerStats.player JOIN PositionStats ON Position.name = PositionStats.player")
    solution = cursor.fetchall()
    

提交回复
热议问题