我想从add_view
为Django Admin中的特定模板调用默认表单。我将使用它的值(我通过表单从模板中恢复)并完成我的工作。我怎么称呼它?
def add_view(self, request, form_url='', extra_context=None):
if request.method == 'POST':
form = defaultForm(request.POST)
if form.is_valid():
field1= formulario.cleaned.data['field1'] + "\n"
#DO MY STUFF
else:
raise raise ValidationError(_("Error1"), code='Error1')
return HttpResponseRedirect("/admin/db/table_name/")
答案 0 :(得分:1)
ModelAdmin有' get_form'方法:
...
default_form = self.get_form(request)
form = default_form(request.POST, request.FILES, instance=None)
...
看看文档: https://docs.djangoproject.com/en/1.9/ref/contrib/admin/#django.contrib.admin.ModelAdmin.get_form