Сценарий:
from django.db import models
class A:
whatever = models.TextField()
class B:
CLASS_VAR = "foo"
comment = models.TextField(blank=True, default="")
another_field = models.ForeignKey(A)
def f(self):
print("hello")
@classmethod
def get_variables(cls):
# TODO
return None
@classmethod
def get_methods(cls):
# TODO
return None
@classmethod
def get_foreign_keys(cls):
# TODO
return None
Я хочу что-то вроде этого:
variables = B.get_variables() # ['comment']
methods = B.get_methods() # ['f', 'get_variables', 'get_methods', 'get_foreign_keys'],
foreign_keys = B.get_foreign_keys() # [{'another_field': 'A'}]
Полагаю, мне следует использовать inspect , но я получаю много ifs и не могу найти нужные фильтры, чтобы получить то, что я хочу.