在Django管理界面中,有没有办法复制一个项目? [英] In the Django admin interface, is there a way to duplicate an item?

查看:501
本文介绍了在Django管理界面中,有没有办法复制一个项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是想知道是否有一种简单的方法来添加在管理界面中复制现有列表的功能?

Just wondering if there is an easy way to add the functionality to duplicate an existing listing in the admin interface?

在数据输入中,我们遇到了一种情况,许多项目与其他项目共享通用数据,并且为了节省时间,快速复制现有列表并且仅更改已更改的数据将是非常好的。使用更好的模型结构将是减少数据重复的一种方法,但是可能会出现以下情况:需要在将来单独更改重复的数据。

In data entry we have run into a situation where a lot of items share generic data with another item, and to save time it would be very nice to quickly duplicate an existing listing and only alter the changed data. Using a better model structure would be one way of reducing the duplication of the data, but there may be situation where the duplicated data needs to be changed on an individual basis in the future.

推荐答案

您可以另存为,只需启用将其添加到您的ModelAdmin:

You can save as by just enabling adding this to your ModelAdmin:

save_as = True

这将用另存为按钮替换保存并添加另一个按钮。 另存为表示对象将被保存为新对象(具有新ID),而不是旧对象。

This replaces the "Save and add another" button with a "Save as" button. "Save as" means the object will be saved as a new object (with a new ID), rather than the old object.

这篇关于在Django管理界面中,有没有办法复制一个项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆