I bind a method post_saveto a model in django, for example, the following code:
def save_mymodel(sender,instance,*args,**kwargs):
print 'save called'
for parameter in instance.parameters.all():
print parameter.name
post_save.connect(save_mymodel, sender=MyModel)
Here are my models:
def MyModel(models.Model):
parameters = models.ManyToManyField(Parameter)
def Parameter(models.Model):
name = models.CharField(max_length=100)
When I try to create MyModeldjango from an administrator with any number of parameters, I get only save calledas output. If I save the same object again MyModelfrom the administrator, all parameters will be printed. What is the difference between a call saveat creation and not at creation? How can I get all the attributes of a model using post_savewhen creating it?
source
share