python - Django post_save not getting many-to-many attributes on create -


i binding post_save method model in django, following code:

def save_mymodel(sender,instance,*args,**kwargs):     print 'save called'     parameter in instance.parameters.all():         print parameter.name  post_save.connect(save_mymodel, sender=mymodel) 

here models:

def mymodel(models.model):     parameters = models.manytomanyfield(parameter)  def parameter(models.model):     name = models.charfield(max_length=100) 

when try create mymodel django admin number of parameters, save called output. if save same mymodel object again admin, parameters printed. difference between calling save on create , not on create? how can make sure attributes of model using post_save on creation?

manytomany fields not participate in model save() method, post_save not recognize m2m changes. detect m2m change, use m2m_changed signal.

django doc m2m_changed.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -