Django admin的进一步定制(添加新对象) [英] Further customization of Django admin (add new object)

查看:112
本文介绍了Django admin的进一步定制(添加新对象)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经对Django管理界面进行了一些配置(内联,过滤器,order_by ...),但是我想在添加新项目时更改保存按钮的行为。看一下我的界面(它是法语,但是应该很容易理解prix:price-enregistrer:save)

I've done a few configurations (inlines, filters, order_by...) to the Django admin interface but I would like to change the behavior of the save button when you add a new item. Take a look at my interface (It is in French, but it should be easy to understand prix:price - enregistrer:save)

我有三个价格字段,一个为当前商品价格,两个为其他为以前的价格。 我想做的是更改并保存当前价格后,价格数据自动进入price2,price2到price3。这样,我总是会看到较早的价格。

I have three price field, one for the current item price and two other for previous prices. What I want to do is when the current price is changed and saved, the data from price goes to price2 and price2 to price3 automatically. Like that, I always see what the older prices were.

也许还有另外一件事:单击save(enregistrer)时,是否可以返回到特定页面,而不返回所有对象列表?

And maybe one more thing : is it possible that when save(enregistrer) is clicked, I can return to a particular page, and not to the list of all objects?

感谢您的帮助!

推荐答案

您可以覆盖如下的管理保存方法:

You can override admin save method like that:

class MyModelAdmin(admin.ModelAdmin):
    def save_model(self, request, obj, form, change):
        # custom stuff here
        obj.save()

这个问题可能保存后帮助您重定向:
通过管理员保存重定向

and this question may help you with redirect after save: Redirect on admin Save

这篇关于Django admin的进一步定制(添加新对象)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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