views:

23

answers:

1

Hello,

Building a Django app.

Class Company(models.Model):
    trucks = models.IntegerField()
    multiplier = models.IntegerField()
    #capacity = models.IntegerField()

The 'capacity' field is actually the sum of (trucks * multiplier). So I don't need a database field for it since I can calculate it.

However, my admin user wants to see this total on the admin screen.

What's the easiest/best way to customize the admin view to allow me to do this?

+1  A: 

define a method on company that returns the product of trucks and multiplier

def capacity(self):
    return self.trucks * self.multiplier

and in the admin model set

list_display = ('trucks', 'multiplier', 'capacity')
Ashok