4
:필드 다이아몬드 패턴 나는 다음과 같은 모델 클래스 계층 구조 데
from django.db import models
class Entity(models.Model):
createTS = models.DateTimeField(auto_now=False, auto_now_add=True)
class Meta:
abstract = True
class Car(Entity):
pass
class Meta:
abstract = True
class Boat(Entity):
pass
class Amphibious(Boat,Car):
pass
불행하게도,이 장고와 함께 작동하지 않습니다
shop.Amphibious.createTS: (models.E006) The field 'createTS' clashes with the field 'createTS' from model 'shop.boat'.
하더라도를 I 보트 초록을 선언하면 도움이되지 않습니다.
shop.Amphibious.createTS: (models.E006) The field 'createTS' clashes with the field 'createTS' from model 'shop.amphibious'.
모델 클래스 계층 구조를 가질 수 있습니까? 다중 상속과 일부 기본 필드를 선언하는 공통 기본 클래스 (models.Model 하위 클래스)
이상하게도'models.AutoField (primary_key = True)'는 문서에 따라 작동합니다. – dmg
@dmg 당신은 [다중 상속] (https://docs.djangoproject.com/en/1.7/topics/db/models/#multiple-inheritance)에있는 문서를 언급하고있는 것 같습니다. 그 속임수는''ID '라는 이름의'AutoField'가''Piece''에 암시 적으로 추가된다는 것입니다. 하위 모델은이 필드를 상속하므로 기본 키가 이미 있습니다. 이것은 새로운 암시 적'id' 필드가 추가되는 것을 막습니다 -> 이름 충돌이 없습니다. 어쨌든 부모 필드를 무시할 수 있다는 의미는 아닙니다. – knbk