I have two models. The model Copy should get the max_length from the model AdSpot without inheriting from it. And after trying multiple times, I failed to make this work:
class AdSpot(models.Model):
title_max_chars = models.IntegerField(default=0)
@property
def title_max_chars_from_adspot(self):
return self.title_max_chars
class Copy(models.Model):
adspot = models.ForeignKey(AdSpot, on_delete=models.PROTECT)
def title_max_chars_from_adspot(self, *args, **kwargs):
return self.adspot.title_max_chars_from_adspot
title = models.CharField('Name', max_length=title_max_chars_from_adspot, default="")
The error is
polls.Copy.title: (fields.E121) 'max_length' must be a positive integer.
What am I missing ?
max_length=int(title_max_chars_from_adspot)TypeError: int() argument must be a string, a bytes-like object or a number, not 'function'max_length=title_max_chars_from_adspot(self)Copymodel must have different columntitlewidth depending on linkedAdSpotrow?savemethod.