开发者

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')
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜