【发布时间】:2019-10-11 17:09:33
【问题描述】:
我正在使用 postgre 数据库,我的数据库中有 10 个通道。这是我使用 channelId 和 userId 作为外键的模型:
class Count(models.Model):
userId = models.ForeignKey(User, on_delete=models.CASCADE)
channelId = models.ForeignKey(News_Channel, on_delete=models.CASCADE)
rate = models.PositiveIntegerField(default=0)
def __str__(self):
return self.channelId.name
class Meta:
ordering = ["-id"]
我希望在创建用户帐户时在表中插入 3 行,将所有 3 个 channelId 和速率值设置为 0。 假设用户注册并获得 userIid 99,然后在表中插入 3 行作为
userId channelId rate
99 1 0
99 2 0
99 3 0
可能的解决方案是什么。
【问题讨论】:
-
你能分享一下你的视图和序列化器吗?
-
嘿@Annabelle,请在以下github urlsgithub.com/imsaiful/backendAPI/tree/master/feed/api中找到视图和序列化程序@
标签: django python-3.x django-models django-views django-authentication