<p>I've got two models: Message and Attachment. Each attachment is attached to a specific message, using a ForeignKey on the Attachment model. Both models have an auto_now DateTimeField called updated. I'm trying to make it so that when any attachment is saved, it also sets the updated field on the associated message to now. Here's my code:</p>

<pre><code>def save(self):
    super(Attachment, self).save()
    self.message.updated = self.updated
</code></pre>

<p>Will this work, and if you can explain it to me, why? If not, how would I accomplish this?</p>

[{'answer_id': 20983, 'author': 'John', 'author_id': 2168, 'author_profile': 'https://Stackoverflow.com/users/2168', 'pm_score': 5, 'selected': True, 'text': '<p>You would also need to then save the message.  Then it that should work.</p>\n'}, {'answer_id': 72359, 'author': 'zgoda', 'author_id': 12138, 'author_profile': 'https://Stackoverflow.com/users/12138', 'pm_score': 1, 'selected': False, 'text': '<p>DateTime fields with auto_now are automatically updated upon calling <code>save()</code>, so you do not need to update them manually. Django will do this work for you.</p>\n'}, {'answer_id': 33449486, 'author': 'Serjik', 'author_id': 546822, 'author_profile': 'https://Stackoverflow.com/users/546822', 'pm_score': 3, 'selected': False, 'text': '<p>Proper version to work is: (attention to last line <code>self.message.save()</code>)</p>\n\n<pre><code>class Message(models.Model):\n    updated = models.DateTimeField(auto_now = True)\n    ...\n\nclass Attachment(models.Model):\n    updated = models.DateTimeField(auto_now = True)\n    message = models.ForeignKey(Message)\n\n    def save(self):\n        super(Attachment, self).save()\n        self.message.save()\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/20927', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1914/']