更新时间:2023-01-30 11:34:41
我认为这可以通过覆盖modB的保存方法。
I think this could be done by overriding the save method of modB.
class modB(models.Model):
moda = models.ForeignKey(modA)
localField = models.CharField(max_length=9,default=moda.asDefault)
def save(self, *args, **kwargs):
if self.pk is None:
if self.moda and not self.localField:
self.localField = self.moda.wantedField
super(modB, self).save(*args, **kwargs)