django - updating an auto_now DateTimeField in a related model -


i update related models timestamp when saving record. here models:

class issue(models.model):     issuetitle = models.charfield()     issuedescription = models.textfield()     issuecreateddatetime = models.datetimefield(auto_now_add=true)      def __unicode__(self):         return self.issuetitle  class issuehistory(models.model):     fk_issueid = models.foreignkey(issue)     issuehistorydetail = models.textfield()     issuehistorycreatedby = models.foreignkey(user)     issuehistorycreateddatetime = models.datetimefield(auto_now=true)      def __unicode__(self):         return self.fk_issueid      def save(self): #1.1         # call parent's `save` function         # record saved normally, without override         super(issuehistory, self).save() #1.2             #this believe should updating "issuecreateddatetime" same datetime 

this post describes want final code wasn't posted (unless misunderstanding it).

to further clarify, desired order of events:

  1. save new issue history record
  2. save() overridden, uses custom
  3. issuehistory record saved
  4. related issue record's "issuecreateddatetime" field updated current datetime

how should this?

 def save(self):     super(issuehistory, self).save() #1.2         # set issue issuecreateddatetime same issuehistory issuecreateddatetime     self.fk_issueid.issuecreateddatetime = self.issuehistorycreateddatetime     # save issue     self.fk_issueid.save() 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -