django, show fields on admin site that are not in model
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开发者_如何学Go 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?
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')
精彩评论