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

查看:24
本文介绍了在 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天全站免登陆