Im working in two models ralated via many to many, here's the relevant code:
class Curso(models.Model):
horarios = models.ManyToManyField(Horario, related_name = 'cursos')
...
def clean(self):
...
self.horarios.all()
def save(self,*args,**kwargs):
self.full_clean()
...
Horarios
has been already defined, now when i try to create an of curso in the admin interface i get an error pointing to self.horarios.all()
:
'Curso' instance needs to have a primary key value before a many-to-many relationship can be used.
And it makes sense as it has not been saved, so my problem is, how do i access the value of horarios
in the current Curso
instance that is being saved?.
thanks in advance