You can solve it using frame inspection:
import inspect
def get_enclosing(name):
# get the frame where the enclosing class in construction is evaluated
outerframe = inspect.getouterframes(inspect.currentframe())[2][0]
return outerframe.f_locals[name]
class Customer(object):
pass
class MyForm(object):
type_constant = 'type'
class Meta:
model = Customer
fields = get_enclosing('type_constant')
Then:
>>> MyForm.Meta.fields
'type'
Note 1: I'm using feature documented in the inspect
module (see http://docs.python.org/2/library/inspect.html). Most probably, this will only work in CPython.
Note 2: unless you really need some magic, parameter passing is probably the right way to do it. I posted my answer to show that it is feasible, but I won't consider it as good code, unless you have a strong reason to avoid passing info from the outer class.