我有以下型號:獲取相關對象的主鍵與繼承的模型在Django
class A(TranslatableModel):
translations = TranslatedFields(
name = models.CharField(max_length=30)
)
f = IntegerField()
class B(A):
def __init__(self, *args, **kwargs):
super(B, self).__init__(*args, **kwargs)
some_field = ...
然後,我創建B的實例,它,我相信,創建A的實例
b = B.objects.create(some_field='aaa', f=15)
如何訪問與b
對象相關的模型A
的對象?有沒有辦法從B獲得A的PK?
沒有工作...我應該改變這種A_與parent_model_name_? – aemdy
是的。在你的例子中,你把它命名爲'a' – second
哦,它應該是全部小寫字母。您能否指定ptr在哪裏記錄?我未能在Google上搜索它。 – aemdy