我有一个模型:
class Trades(models.Model):
userid = models.PositiveIntegerField(null=True, db_index=True)
positionid = models.PositiveIntegerField(db_index=True)
tradeid = models.PositiveIntegerField(db_index=True)
orderid = models.PositiveIntegerField(db_index=True)
...
我想执行下一个查询:
select *
from trades t1
inner join trades t2
ON t2.tradeid = t1.positionid and t1.tradeid = t2.positionid
能否使用Django ORM而不是hack来实现这个功能呢?谢谢!
parent = models.ForeignKey('self',on_delete=models.CASCADE,db_column='parent_id',null=True, blank=True)
。 - Keith John Hutchison