Answer the question
In order to leave comments, you need to log in
How to redefine a property in the heir?
Can anyone explain how this is resolved?
Why does saving work in the child method, but the value of the parent remains in the content property?
And is it possible to somehow override the property?
from django.db import models
class Father(models.Model):
COST = 100
content = models.TextField(max_length=COST)
class Meta:
abstract = True
def save(self, *args, **kwargs):
if self.COST > 200:
self.action = True
super(Father, self).save(*args, **kwargs)
class Children(Father):
COST = 500
action = models.BooleanField(default=False)
Answer the question
In order to leave comments, you need to log in
try declaring the action field in the parent class:
class Father(models.Model):
COST = 100
content = models.TextField(max_length=COST)
action = models.BooleanField(default=False)
class Meta:
abstract = True
def save(self, *args, **kwargs):
if self.COST > 200:
self.action = True
super(Father, self).save(*args, **kwargs)
class Children(Father):
COST = 500
Try:
class Children(Father):
COST = 500
action = models.BooleanField(default=False)
class Meta:
content = models.TextField(max_length=COST)
class Father(models.Model):
COST = 100
content = models.TextField(max_length=self.COST)
...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question