django-models - Django 模型将 2 个 Foreinkeys 保存到同一个模型
问题描述
按照此链接和文档,它仍然无法以某种方式保存具有 2 个 Foreinkeys 的对象。
class Photo(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE, null=True) #User.photo_set.all() returns all Photo objects of the photo
photoURL = models.CharField(max_length=256, null=True)
secondPhoto = models.OneToOneField('self', on_delete=models.PROTECT, null=True, blank=True)
timestamp = models.DateTimeField(auto_now_add=True)
description = models.CharField(max_length=1000, null=True)
is_private = models.BooleanField(default=False)
class Clash(models.Model):
win_photo = models.ForeignKey(Photo,on_delete=models.PROTECT, related_name="wins", null=True)
loss_photo = models.ForeignKey(Photo,on_delete=models.PROTECT, related_name="losses", null=True)
is_private = models.BooleanField(default=False) #we will filter those out for user quality calculations
解决方案
推荐阅读
- hbase - 如何在 Apache phoenix 的字符串中识别/搜索“-”?
- javascript - 从谷歌图书 api 中分离元素
- python - 针对客户端应用程序在 python Web api 上的 Azure 广告访问令牌验证
- android - 使用uri加载本地大图时,速度很慢。我该如何优化它?
- python-3.x - TypeError:'str'对象不支持项目分配google api
- r - 当变量等于 0 时擦除行但当它是 NA 时不擦除行,或者当 R 中的两列等于 NA 时
- xml - XSLT 将请求 XML 转换为响应 XML
- c++ - 访问作为非类型模板参数传递的 std 数组元素会在 msvc 上提供非编译时常量值
- c# - ASP.NET Core MVC / RAZOR - 等效于 @Section 脚本的样式
- python - 如何从 Python 中的 2 个不同列表计算中位数