How can I call model methods or properties from Django Admin?
- by kg
Is there a natural way to display model methods or properties in the Django admin site? In my case I have base statistics for a character that are part of the model, but other things such as status effects which affect the total calculation for that statistic:
class Character(models.Model):
base_dexterity = models.IntegerField(default=0)
@property
def dexterity(stat_name):
total = self.base_dexterity
total += sum(s.dexterity for s in self.status.all()])
return total
It would be nice if I could display the total calculated statistic alongside the field to change the base statistic in the Change Character admin page, but it is not clear to me how to incorporate that information into the page.