python - Save in Two Models with post_save -


i have problem :

exists 3 models in app:

class cliente(models.model):     #fields here ...  class imovel(models.model):     #more fields and..     dono = models.foreignkey(cliente)  class captacao(models.model):     #here, have fields of others models (cliente , imovel) 

i want populate models "cliente" , "imovel" through of model "captacao"... know there post_save this, not know how this, save fields in each respective model.

thanks,

if dont have cliente yet, can create him, using imovel data:

def save_in_other_models(sender, instance, created, **kwargs):     cliente = cliente.objects.create(         name=instance.name,         ident=instance.ident,     )     imovel.objects.create(         dono=cliente     )  models.signals.post_save.connect(save_in_other_models, sender=captacao) 

---------------- ** ---------------- ** ---------------- ** ---------------- ** ---------------- ** ---------------- ** ---------

if have cliente instance in relation captacao:

** , create new imovel using cliente relation imovel

def save_in_other_models(sender, instance, created, **kwargs):     imovel.objects.create(         dono=instance.cliente     )  models.signals.post_save.connect(save_in_other_models, sender=captacao) 

Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -