Search code examples
pythondjangovisibilityinstance-variablesclass-variables

how to view class variables from an inner class in python


I have the following class with inner class and class variable:

class MyForm(forms.ModelForm):

    type_constant = 'type'

    class Meta:

        model = Customer
        fields = ('type')

I would like to replace 'type' in the fields variable to the type constant in the super class. How do I use the type_constant in the fields variable value?


Solution

  • One way is to pass the outer class member as a parameter. I see no better way as far as I know. The inter class has no information about which class includes it. And python has not offer any specific keywords or methods for outer class accessing. So it is better to do it with parameter passing.

    __init__(self, other=None)
    

    in inter class.