1

I've got several ModelAdmin classes and I'd like to do the same action when save the model so I created mixin object for this purpose:

class SaveModelMixin(object):
    def save_model(self, request, obj, form, change):
        if obj.is_executed and 'is_executed' in obj.changed_data:
            obj.date_execution = datetime.date.today()
        super(self.__class__, self).save_model(request, obj, form, change)

And when I try to save object in admin, this method just runs itself again and again, and I can't figure out why.

Dmitrii Mikhailov
  • 4,787
  • 6
  • 41
  • 66

1 Answers1

3

Looks like your super() call is incorrect, try this:

super(SaveModelMixin, self).save_model(request, obj, form, change)

See explanation here: How to avoid infinite recursion with super()?

Also see:

Community
  • 1
  • 1
alecxe
  • 441,113
  • 110
  • 1,021
  • 1,148