派生モデルが画像やテキストなどのコンテンツブロックを保持できるようにする抽象Containerクラスがありますが、これらも個別のモデルです。dbの整理のために、これらのモデルのテーブルにcontent_block_image、content_block_textなどのラベルを付ける必要があります。
しかしapp_label = 'content_block'
、コンテンツモデルのメタクラスで指定すると、syncdb中にエラーが発生します。
content.event:'content'は、インストールされていないか抽象であるモデルContentとm2mの関係にあります。
私は次の基本クラスを次のように宣言しています。
# base.py
class Content(models.Model):
tags = models.TextField(_('tags'), blank=True)
user = models.ForeignKey(User)
content_type = models.ForeignKey(ContentType,
related_name='%(class)s_content_set')
container_type = models.ForeignKey(ContentType)
container_id = models.PositiveIntegerField()
container = generic.GenericForeignKey('container_type', 'container_id')
class Meta:
app_label = 'content_block'
class Container(models.Model):
content_type = models.ForeignKey(ContentType,
related_name='%(class)s_container_set')
content = generic.GenericRelation('Content',
content_type_field='container_type',
object_id_field='container_id')
class Meta:
abstract = True
次に、私のモデルで、次のようなコンテナと呼ぶモデルを宣言しています。
# models.py
class Event(Container):
title = models.CharField(max_length=100)
start = models.DateTimeField()
end = models.DateTimeField()
app_label
syncdbを削除すると、問題なく実行されます。app_labelは単なるラベルではないようです。
コンテンツ基本クラスセットのapp_labelを使用してこれを実行する方法についてのアイデアはありますか?