本文介绍了Django管理员:'添加'页面,想在一个页面上添加多个对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

国家(models.Model):
name = fields.CharField()

在管理员中,我想为Country显示多个表单,因此我可以一次添加多个不同的国家/地区对象。我不知道从哪里开始?请帮助,谢谢。

解决方案

我无法想到在管理员中有任何办法。管理员是一个现成的接口,用于编辑单个对象(以及可选地,与该对象相关的多个对象 ),但不能一次编辑多个对象。



如果需要,请使用表单编写自己的视图。


class Country(models.Model):
    name = fields.CharField()

In admin, I want to display multiple forms for Country so I can add multiple different country objects at once. I don't know where to start? Please help, thanks.

解决方案

I can't think of any way to do this inside the admin. The admin is a ready-made interface for editing single objects (and, optionally, multiple objects related to that object), but doesn't give you any way to edit multiple objects at once.

If you need this, write your own view using a formset.

这篇关于Django管理员:'添加'页面,想在一个页面上添加多个对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-05 00:44