I'm trying to create an identificator for my Scheduler model which depends on ManyToManyField
of this model.
The problem is that when I override save
method, the first time (when object is created) it causes problems. It should be saved first. On the other hand when I create a post_save
signal, the problem is that I have to save
the model inside this signal which ends with 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.
Do you have any ideas?