Django多表继承阻塞了模型定义中泄漏的变量 类父级(models.Model): 通过 类RebelliousChild(父级): parent_fields=[[parent.\u meta.\u fields()中的\uuuux的\uuuux.name]
Django1.3回应:Django多表继承阻塞了模型定义中泄漏的变量 类父级(models.Model): 通过 类RebelliousChild(父级): parent_fields=[[parent.\u meta.\u fields()中的\uuuux的\uuuux.name],django,python-2.7,django-models,list-comprehension,multi-table-inheritance,Django,Python 2.7,Django Models,List Comprehension,Multi Table Inheritance,Django1.3回应: django.core.exceptions.FieldError: Local field '_RebelliousChild__x' in class 'RebelliousChild'clashes with field of similar name from base class 'Parent' FieldError: Local field u'id' in class 'RebelliousChild' clashes with field of
django.core.exceptions.FieldError: Local field '_RebelliousChild__x'
in class 'RebelliousChild'clashes with field of similar name from base class 'Parent'
FieldError: Local field u'id' in class 'RebelliousChild' clashes with field
of similar name from base class 'Parent'
Django1.5回应:
django.core.exceptions.FieldError: Local field '_RebelliousChild__x'
in class 'RebelliousChild'clashes with field of similar name from base class 'Parent'
FieldError: Local field u'id' in class 'RebelliousChild' clashes with field
of similar name from base class 'Parent'
我的第二个反应(在尝试将变量设置为私有后)是删除该变量(这是有效的)
parent\u fields=[\uuuuux.name在parent.\u meta.\u fields()中为\uuuux命名]
德鲁
列出理解。 Django似乎有点牵扯其中,因为Django 1.5也有同样的问题。但在这两种情况下,泄漏的属性名
\u RebelliousChild\uuux
都没有在父级上定义
这是怎么回事
PS
使用“list(Parent.\u meta.\u fields()中x的x.name)”比使用“del x”更漂亮。请参阅上述关于发电机不泄漏其控制变量的说明
请看这里:
简而言之,您不需要将父字段应用于子字段(它们已经存在,但在不同的表中),您可以直接在RebelliousChild实例上访问它们