我有 2 个 django 模型:
class Message(models.Model):
msg = models.CharField(max_length=200)
date = models.DateTimeField(auto_now_add=True)
class Thread(models.Model):
messages = models.ManyToManyField(Message)
是否可以通过相当于 SQL 的 Django ORM 进行一次查询:
SELECT Message.msg, Message.date
FROM Message, Thread
WHERE Message.id IN Thread.messages
AND Thread.id IN (1,2,3)
ORDER BY Message.date
LIMIT 10