首页 > 解决方案 > 如何为 Django 内联模型管理员添加总行?

问题描述

我想在 Django Admin 内联模型中添加一行,我可以在其中汇总计算的税后金额。

我有两个模型:Appointments 和 Invoice_Line,在管理员中我将 Invoice_Line 模型显示为 Appointments 的内联(模型管理员注册如下所示):

管理员.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]

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

在此处输入图像描述

我想修改内联以包含一个总计行,我可以在其中为所有行添加“税后总计”。我该怎么做呢?

我是 Django 新手,非常感谢我能得到的任何帮助。

标签: pythondjango-modelsdjango-templates

解决方案


推荐阅读