Я пытаюсь создать некоторые объекты модели ABC из метода сохранения модели XYZ, когда создается объект моделей XYZ.См. Код ниже для справки:
Class XYZ(models.Model):
name = models.CharField(max_length=150)
#Other Feilds
def save(self, *args, **kwargs):
self.match_tick = self.match_date.timestamp()
contest_obj_1 = ContestDetail(
contest_of_ABC=self,
contest_name="₹1000 Winnnings",
filled_status = False,
)
contest_obj_1.save()
super(MatchDetail, self).save(*args, **kwargs)
Class ABC(models.Model):
contest_of_ABC = models.ForeignKey(XYZ)
contest_name = models.CharField(max_length=100)
filled_status = models.BooleanField(default=False)
А вот строки ошибок:
File "./center/models.py", line 47, in save
contest_obj_1.save() File "./center/models.py", line 203, in save
super(ContestDetail, self).save(*args, **kwargs) File "/home/FightBack/.virtualenvs/ENV/lib/python3.5/site-packages/django/db/models/base.py", line 762, in save
"unsaved related object '%s'." % field.name ValueError: save() prohibited to prevent data loss due to unsaved related object 'contest_of_ABC'.