0
の多型の関係を説明して、この接続を説明する方法を教えてください: はジャンゴ
をレコードの異なるタイプ(タイプ1、タイプ2またはタイプ3)があることができたテーブルがあります。接続を行うと、私は例Type2のために、種類を入力したいものを選択する方法
models.py
from django.db import models
from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation
from django.contrib.contenttypes.models import ContentType
class General(models.Model):
field1 = models.CharField(max_length=512, blank=True, null=True)
field2 = models.CharField(max_length=512, blank=True, null=True)
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object = GenericForeignKey('content_type', 'object_id')
class Meta:
db_table = 'General'
class Type1(models.Model):
name = GenericRelation(Product)
address = models.CharField(max_length=512, blank=True, null=True)
number = models.CharField(max_length=256, blank=True, null=True)
class Meta:
db_table = 'Type1'
?