Ale*_*ord 5 python django many-to-many abstract django-orm
这里有一个有趣的..我缩短了模型以使其更容易理解..
class Participant(Person):
passport_number = models.IntegerField(verbose_name=_('Passport Number'), db_column=u'PassportNumber')
class Meta:
db_table = u'Participant'
class Journey(BaseModel):
participants = models.ManyToManyField(Participant, related_name='%(app_label)s_%(class)s_participants', through=u'ParticipantJourney')
class Meta:
abstract = True
class PlaneJourney(Journey):
flight_number = models.CharField(max_length=16, verbose_name=_('Flight Number'), db_column=u'FlightNumber')
class Meta:
db_table = u'PlaneJourney'
class ParticipantJourney(BaseModel):
participant = models.ForeignKey(Participant, verbose_name=_('Participant'), db_column=u'ParticipantId')
journey_content_type = models.ForeignKey(ContentType, related_name='journey_content_type')
journey_object_id = models.PositiveIntegerField()
journey = generic.GenericForeignKey('journey_content_type', 'journey_object_id') # models.ForeignKey(Journey, verbose_name=_('Journey'), db_column=u'JourneyId')
payment_content_type = models.ForeignKey(ContentType, related_name='payment_content_type')
payment_object_id = models.PositiveIntegerField()
payment = generic.GenericForeignKey('payment_content_type', 'payment_object_id') # models.ForeignKey(Payment, verbose_name=_('Payment'), db_column=u'PaymentId')
class Meta:
db_table = u'ParticipantJourney'
Run Code Online (Sandbox Code Playgroud)
ParticipantJourney 模型将参与者与旅程联系起来,现在旅程是抽象的,因为它可以通过多种不同的运输方式进行,每种方式都有自己的领域。我认为这个设置是正确的,但我收到以下错误消息:
错误:一个或多个模型未验证:kandersteg.planejourney:'participants' 是通过模型 ParticipantJourney 手动定义的 m2m 关系,它没有 Participant 和 PlaneJourney 的外键
我需要保留链接表的手动定义,以便我也可以将付款链接到所述旅程,因此我真的不知道下一步该去哪里,如果有人能透露一些信息,我会非常感谢!
干杯,亚历克斯
| 归档时间: |
|
| 查看次数: |
2043 次 |
| 最近记录: |