开发者

Django ModelForm: How to override or check for "save_as"

I need to add som开发者_运维知识库e customizations for the case that a instance in Django Admin is "saved_as" a copy. Can I do that in save(), if so how do I check for the save_as kwarg? Or is there a save_as() method I can override somewhere. I was not able to find any information about the differences in the process between a regular save() and one with save_as = True.

Can someone point me to an example or give me an hint where to go?

Thank you very much for your time!

:)


http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.change_view

The Save as New button is a submit element with a specific name, _saveasnew, meaning you can check whether that button was pressed via the presence of the _saveasnew POST parameter.

def change_view(self, request, object_id, extra_context=None):        
    if '_saveasnew' in request.POST:
        # custom logic for save as new
        print "I am saved as new"
    return super(ModelAdmin, self).change_view(request, object_id, extra_context)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜