2
は、以下の例を検討しているテーブル見つける:ジャンゴ:継承階層内のフィールド
class Base(models.Model):
myfield = models.CharField()
class Derived(Base):
pass
を今、ベースと派生クラスは、データベース内の別のテーブルを持っています。
私の質問は、myfieldのどのテーブルに属しているかを調べる方法です。
は、以下の例を検討しているテーブル見つける:ジャンゴ:継承階層内のフィールド
class Base(models.Model):
myfield = models.CharField()
class Derived(Base):
pass
を今、ベースと派生クラスは、データベース内の別のテーブルを持っています。
私の質問は、myfieldのどのテーブルに属しているかを調べる方法です。
使用_meta.get_fields_with_model()
方法:
for field, model in Derived._meta.get_fields_with_model():
if field.name == 'myfield':
model = model or Derived
print 'myfield belongs to %s' % model._meta.db_table
答えを探しながら、私が見つけたDjangoの上のいくつかのドキュメント:http://django-model-internals-reference.readthedocs.org/en/latest/get_all_field_names.html – Joonas