[Answered ]-Override Class Attribute, with a generic way to refer to class

2👍

Best approach would be to replace the save function to set employees if it’s blank at the time of saving.

Something like:

class Company(models.Model):
    ...
    def save(self, *args, **kw):
       if self.employees is None:
            self.employees = self.DEFAULT_EMPLOYEES
       super(Company, self).save(*args, **kw)

the define DEFAULT_EMPLOYEES in each child class as you have done.

The alternative is modifying the metaclass which is probably overkill.

0👍

Define a classmethod on your parent:

@classmethod
def showDefaultEmployees(cls):
    return cls.DEFAULT_EMPLOYEES

Then just call it from your class instance

BestBuy.showDefaultEmployees()

Leave a comment