【发布时间】:2013-01-23 02:27:23
【问题描述】:
我将中间模型用于“ManyToManyField using the through”
通常,如果我不使用中间字段,m2m 关系将是唯一的,并且不能有重复的数据。
在我使用中间模型之后。 m2m之间的关系可以有相同的数据。像这样
| | ['0'] (
| | | addToProfile => Array (0)
| | | (
| | | )
| | | endDate = NULL
| | | feedType = "N"
| | | id = 1
| | | info = "Big Kuy No Fear"
| | | likeMaker => Array (3)
| | | (
| | | | ['0'] = "/api/v2/user/2/"
| | | | ['1'] = "/api/v2/user/2/"
| | | | ['2'] = "/api/v2/user/2/"
| | | )
| | | like_count = "3"
我正在建立一个社交网络。所以这是我的提要对象,它有 3 个 like_counts 。但是这三个like来自同一个用户“/api/v2/user/2/”
我尝试在 m2m 字段中添加“unique=True”属性,但 django 出现错误,因为它最初没有授予将“unique”属性添加到 m2m 字段的权限。谁能帮帮我?
【问题讨论】:
-
试着澄清你想要什么,我无法通过阅读你的问题来理解它。
-
我想让 m2m 字段是唯一的,例如 a---x a---y a---z b---x b---x
-
@luistm 你现在明白我的问题了吗。
-
您看不到 django 文档的链接,是吗?为什么不创建自己的 m2m 表?
标签: django many-to-many tastypie relation