kingadmin后台新增页面开发
Posted fqh202
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了kingadmin后台新增页面开发相关的知识,希望对你有一定的参考价值。
1、路由配置
url(r'^(w+)/(w+)/add$', views.add_obj, name='add_obj')
2、视图函数
def add_obj(request, app_name, model_name):
"""增加新对象 """
admin_class = site.enable_admins[app_name][model_name]
dynamic_form = create_model_form(admin_class, add=True)
if request.method == 'GET':
form_obj = dynamic_form()
return render(request, 'kingadmin/add_obj.html', locals())
elif request.method == 'POST':
form_obj = dynamic_form(data=request.POST)
if form_obj.is_valid():
form_obj.save()
return redirect('/kingadmin/%s/%s' % (app_name, model_name))
errors = form_obj.errors
return render(request, 'kingadmin/add_obj.html', locals())
3、前端页面
{% extends 'kingadmin/change_info.html' %}
{% block readonly_fields_display %}
{% endblock %}
{% block delete_button %}
{% endblock %}
4、页面新增按钮
<a href="{% url 'add_obj' app_name model_name %}" style="float: right">
<button type="submit" class="btn btn-default form_btn">ADD {% get_names admin_class %}
<span class="glyphicon glyphicon-plus"></span></button>
</a>
@register.simple_tag
def get_names(admin_class):
"""获取表名,有中文则获取中文显示"""
model_class = admin_class.model
if model_class._meta.verbose_name:
return model_class._meta.verbose_name
return model_class._meta.model_name
以上是关于kingadmin后台新增页面开发的主要内容,如果未能解决你的问题,请参考以下文章
CRM项目实战-kingadmin model obj list 页面开发