django 每个日期都是唯一的
首先,让我向您展示我的模型:
class ChannelStatus(models.Model):
channel = models.ForeignKey(Channel,unique_for_date="date")
date = models.DateField()
platform = models.ManyToManyField(Platform)
现在,当我想要创建一个 ChannelStatus 条目时,不能有多个条目具有相同的频道和日期。现在,我想将其更改为每个条目的唯一性渠道到每个平台的日期,因此不同平台可以有多个具有相同日期的相同渠道。我怎样才能做到这一点?
First of all let me show you my model:
class ChannelStatus(models.Model):
channel = models.ForeignKey(Channel,unique_for_date="date")
date = models.DateField()
platform = models.ManyToManyField(Platform)
Right now, when I want to make an ChannelStatus entry, there cant be more than one entry which is the same channel and the date.Now, I want to change this as the uniquess of each channel to the date for each platform, so different platforms can have several same channel with same date. How can I achieve this ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,那这个呢。 (未经测试的代码。)
[旧答案]
顺便说一句,我会更改日期中第二个字段的名称,您正在使用日期时间,有时会执行
from datetime import date
,您将得到被咬Ok, what about this. (Untested code.)
[Old answer]
Btw, I would change the name of the second field from date, one you are working with datetime, and sometime do
from datetime import date
, you are going to get bitten