如何为Django内联模型管理员添加总行?

2024-05-16 10:19:40 发布

您现在位置:Python中文网/ 问答频道 /正文

我想在Django管理内联模型中添加一行,在这里我可以计算出税后的总金额

我有两个模型:约会和发票行,在管理中,我将发票行模型显示为内联到约会(模型管理员注册如下所示):

管理员.py:

class Inv_LineInline(admin.TabularInline):
    model = Invoice_Line
    extra = 1
    fields = ['item_desc','item_quantity','tip_amount','item_price','total_before_tax','stax_rate','stax_amount','total_after_tax']
    readonly_fields = ['item_price','total_before_tax','stax_rate','stax_amount','total_after_tax']


@admin.register (Appointment)
class Appointment(admin.ModelAdmin):
    list_display = ('appointment_ref','create_date','appointment_date',
                    'appointment_time','assigned_associate',
                    'check_in', 'appointment_status', 'last_name', 'first_name')
    list_editable = ('assigned_associate','check_in')
    search_fields = ('appointment_ref','create_date','appointment_date', 'appointment_time','requested_associate__associate','assigned_associate__associate','check_in', 'last_name', 'first_name')
    list_filter = ('check_in','appointment_status',)
    inlines = [Inv_LineInline]

管理更改模板如下链接所示:

enter image description here

我想修改内联以包含一个totals行,在这里我可以为所有行添加“税后合计”。我该怎么做呢

我是刚到Django的,如果能得到任何帮助,我将不胜感激


Tags: namein模型fieldsdateadmincheckitem