A
A
Antigo_ptz2017-02-08 11:37:49
Django
Antigo_ptz, 2017-02-08 11:37:49

How to solve the problem of calling super() from a function?

Hello!
There is a serializer class OrgLegalFormSerializer:

class OrgLegalFormSerializer(serializers.ModelSerializer):
   
    def update(self, instance, validated_data):
        return update_with_activation_check(self, instance, 'code', **validated_data)

    class Meta:
        model = OrgLegalForm
        fields = '__all__'

This class overrides the update method. In this method, I call my update_with_activation_check method.
This method of mine is outside of any class.
def update_with_activation_check(self, instance, unique_code_field=None, **validated_data):
#какой-то код
   return super().update(instance, validated_data)

The problem is that when super().update(instance, validated_data) is called, the super(): __class__ cell not found error pops up. How should the code be improved?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Mindlin, 2017-02-08
@kgbplus

I'll post it here for anyone who needs it:

class GrandFather():
    def update(self, cls):
        return super(cls, self).update()

class Father():
    def update(self):
        print("Luke, I am your father!")

class Son(Father,GrandFather):
    def test(self):
        GrandFather.update(self,Son)

test = Son()

test.test()

26d432e78e704aafb61013161477bc28.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question