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()
- [Answered ]-Combine built-in tags in templates with variables
- [Answered ]-How to deal with a large queryset in Django
Source:stackexchange.com