在this link和文档之后,它仍然无法以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