Self Referencing Class Definition in python
python
Solution
i've got a metaclass that reads this information and does some setup
Most frameworks that use metaclasses provide a way to resolve this. For instance, Django:
subplan = ForeignKey('self')
Google App Engine:
subplan = SelfReferenceProperty()
The problem with solutions like tacking an additional property on later or using `__new__` is that most ORM metaclasses expect the class properties to exist at the time when the class is created.
Problem
is there any way to reference a class name from within the class declaration? an example follows: ``` class Plan(SiloBase): cost = DataField(int) start = DataField(System.DateTime) name = DataField(str) items = DataCollection(int) subPlan = ReferenceField(Plan) ``` i've got a metaclass that reads this information and does some setup, and the base class implements some common saving stuff. i would love to be able to create recursive definitions like this, but so far in my experimentation i have been unable to get the effect i desire, usually running into a "Plan is not defined" error. I understand what is happening, the name of the class isn't in scope inside the class.