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
  • 5,053
  • 7
  • 43
  • 69

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
  • 462,703
  • 120
  • 1,088
  • 1,195