How can I call model methods or properties from Django Admin?

Posted by kg on Stack Overflow See other posts from Stack Overflow or by kg
Published on 2010-05-19T19:08:45Z Indexed on 2010/05/19 19:10 UTC
Read the original article Hit count: 325

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.

© Stack Overflow or respective owner

Related posts about django

Related posts about django-models