Try this, it should create the System object only once, during the creation of the test object:
class Test(models.Model):
nameS= models.CharField(max_length=40)
def save(self, *args, **kwargs):
if not self.pk:
super(Test, self).save(*args, **kwargs)
Test2.objects.create(test=self)
else:
super(Test, self).save(*args, **kwargs)
You may need to fill in the field field1because it cannot be NULL according to your current setting.
source
share