[Answer]-Django automatically enter data in table 2 when entering data in a table 1

1👍

You can achieve this by overriding the predefined model method save():

class M1(models.Model):
    ...

    def save(self, *args, **kwargs):
        super(M1, self).save(*args, **kwargs) # Call the "real" save() method.

        m2 = M2(m1=self, m2code=self.m1code, m2title=self.m1title, m2description=self.m1description)
        m2.save()

Leave a comment