0
我正在嘗試爲我的調度程序模型創建標識符,該模型取決於此模型的ManyToManyField
。當創建對象時,覆蓋保存方法會引發異常
問題是,當我重寫save
方法時,第一次(當創建對象時)會導致問題。它應該先保存。就當我創建post_save
信號另一方面,問題是,我必須save
這個信號與INFI
class Scheduler(models.Model):
weekhours = models.ManyToManyField('WeekHour', related_name='schedulers')
identificator = models.TextField(null=True,blank=True)
def save(self,*args,**kwargs):
if self.weekhours.all():
identificator = ','.join([str(x.hour) for x in self.weekhours.all().order_by('hour')])
self.identificator = identificator
super(Scheduler, self).save(*args, **kwargs)
ValueError:
"<Scheduler: None>"
needs to have a value for field "scheduler" before this many-to-many relationship can be used.
你有什麼想法結束裏面的模型?