[Django]-Django change foreign key data and save

3👍

You could override the save method or just create a custom method.

class Article(models.Model):

    ...

    # Overriding save
    def save(self, *args, **kwargs):
        self.reporter.save()
        super(Article, self).save(*args, **kwargs)

    # Creating a custom method 
    def save_related(self):
        self.reporter.save()
        self.save()

I suggest you create a custom method because it doesn’t introduce unexpected behavior in save()

Leave a comment