I want the default modB localField value to be the modA wantedField value corresponding to the foreign key. This would gives :
class modA(models.Model):
wantedField = models.CharField(max_length=9)
[ ... other fields ...]
def asDefault():
return wantedField
class modB(models.Model):
moda = models.ForeignKey(modA)
[ ... other fields ...]
localField = models.CharField(max_length=9,default=moda.asDefault)
def save(self, *args, **kwargs):
if self.moda and not self.localField:
self.localField = self.moda.wantedField
super(modB, self).save(*args, **kwargs)
Also, would the approach be the same with any other field type ?
Anyway, for the moment it returns:
AttributeError: 'ForeignKey' object has no attribute 'asDefault'