编辑新增等页面对应的modelform为ModelFormAdminView

(xadmin.views.edit.ModelFormAdminView)

 

通过源码分析,新增对象的template属性为add_form_template, 修改为change_form_template, 代码如下:

class ModelFormAdminView(ModelAdminView):
    form = forms.ModelForm
    formfield_overrides = {}
    readonly_fields = ()
    style_fields = {}
    exclude = None
    relfield_style = None

    save_as = False
    save_on_top = False

    add_form_template = None
    change_form_template = None

  

因此,如果要定制新增/修改页面,直接将对应的template拷贝到 app/templates/app/下修改, 然后指定为这个template即可。

修改对应的adminx.py文件的对应类,demo如下:

class CardGroupAdmin(object):
	list_display=['create_date', 'code', 'name', 'country', 'area', 'supplier', 'net_type', 'status', 'notify_status' ]
	search_fields=['code', 'name']
	list_filter=['status',  'country', 'area', 'supplier', 'net_type']
	#readonly_fields=['code','country', 'area', 'supplier', 'net_type']
	#form_template = 'card_pool/form.html'
	add_form_template = 'card_pool/form.html'
	change_form_template = 'card_pool/form.html'
xadmin.site.register(CardGroup, CardGroupAdmin)