Monday 15 April 2013

django - post_save error Message' has no attribute -


I have tried to use the post_save signals for the first time I've read the documents, But still some advice is needed.

I am trying to designate my model area 'charge'.

  @receiver (post_save, sender = message) def my_handler (sender, ** kwargs): if not sender. Charge: Sender (sender) sender.save ()   

However, this error message gives' no attribute 'charge', but the charge exists in the message is!

sender here message is class, not Saving example. The actual example is passed in the form of keyword logic example . Also, with post_save , if you are not careful, you will get yourself in the infinite loop. pre_save . Better to use def my_handler (sender, ** kwargs) @receiver (pre_save, sender = message) to better: Example = kwargs ['instance'] If not for example. In charge: example.charge = instance.length () # There is no need to save, because we first press the database by slipping the value into #.

No comments:

Post a Comment