【发布时间】:2019-11-28 20:13:27
【问题描述】:
我有这两个对象(省略了不相关的字段):
class Item(models.Model):
id = models.BigAutoField(primary_key=True)
group_id = models.IntegerField(blank=True, null=True)
class Observation(models.Model):
item_id = models.IntegerField(blank=True, null=True)
group_id = models.IntegerField(blank=True, null=True)
加入他们是基于观察的 item_id 或 group_id:
SELECT o.*
FROM observations o
JOIN items i ON (i.id = o.item_id OR i.group_id = o.group_id)
...
这种类型的多对多关系可以在模型中描述还是我需要编写自定义字段?
【问题讨论】:
标签: python django many-to-many django-orm