Django JOIN query without foreign key

前端 未结 3 1665
失恋的感觉
失恋的感觉 2021-02-20 10:37

Is there a way in Django to write a query using the ORM, not raw SQL that allows you to JOIN on another table without there being a foreign key? Looking through the documentatio

3条回答
  •  一向
    一向 (楼主)
    2021-02-20 11:17

    No, there isn't an effective way unfortunately.

    The .raw() is there for this exact thing. Even if it could it probably would be a lot slower than raw SQL.

    There is a blogpost here detailing how to do it with query.join() but as they themselves point out. It's not best practice.

提交回复
热议问题