Python class defined in the same file as another class - how do you get access to the one defined later in the file?

django, django-models, python

Solution

So the answer was to use qoutes

B = fields.ForeignKey('api.resources.B', 'B')

Problem

I'm very new to Python, I figure this question should be easy to answer. My problem simplified is this... I have 2 classes in a File class A and class B. Class A is defined first in the file and class B is defined second. ``` class A ... class B ... ``` How do I get access to class B with class A? ``` class A something = B class B somethingElse = A ``` Here is the actual code I'm trying to fix ``` class FirstResource(_ModelResource): class Meta(_Meta): queryset = First.objects.all() resource_name = 'first' allowed_methods = ['get','put'] filtering = { 'a': ALL_WITH_RELATIONS, 'b': ALL_WITH_RELATIONS, 'c': ALL_WITH_RELATIONS, } ordering = ['apt'] # this is the line that would fix everything second = fields.ForeignKey(SecondResource, 'second', null=True, blank=True, default=None, full=True) ... class SecondResource(_ModelResource): class Meta(_Meta): queryset = Second.objects.all() resource_name = 'second' execute_methods = ['get', 'post'] filtering = { 'name': ['exact'], 'leader': ['exact'], } super = fields.ForeignKey(FirstResource, 'super', null=True, blank=True, default=None, full=True) leader = fields.ForeignKey(FirstResource, 'leader', null=True, blank=True, default=None, full=True) ... ``` With no pre-declaring in Python I'm really not sure how to solve this problem. The First in models.py has a ForeignKey of Second, and Second has 2 Foreign keys of First. Moving A below B does not solve the problem since B also needs A. I didn't write the code I'm simply trying to fix it - I need the 'second' foreign key back when I do a 'get' for the resource in both classes.

Original source