3

I need to add some 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!

:)

Ryan Castillo
  • 1,135
  • 10
  • 22
user640916
  • 33
  • 3

1 Answers1

2

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)
Yuji 'Tomita' Tomita
  • 115,817
  • 29
  • 282
  • 245