我对 Python 很陌生,我认为这个问题应该很容易回答。
我的问题简化是这样的......
我在文件类 A 和类 B 中有 2 个类。首先在文件中定义类 A,然后在第二个定义类 B。
class A
...
class B
...
Run Code Online (Sandbox Code Playgroud)
如何通过 A 类访问 B 类?
class A
something = B
class B
somethingElse = A
Run Code Online (Sandbox Code Playgroud)
这是我正在尝试修复的实际代码
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 …Run Code Online (Sandbox Code Playgroud)