0

GenericForeignKey を使用したモデルがあります。

class Breadcrumbs( models.Model ):

    title = models.CharField( max_length = 256 )

    limit = models.Q( app_label = 'news', model = 'NewsPost' )

    content_type = models.ForeignKey( ContentType, limit_choices_to = limit )
    object_id = models.PositiveIntegerField()
    content_object = generic.GenericForeignKey( 'content_type', 'object_id' )

    class Meta:
        db_table = 'breadcrumbs'

デフォルトでは、object_id の入力テキスト ウィジェットがあります。

ここに画像の説明を入力

オプションで選択する方法は?また、デフォルトで NewsPost ID (または NewsPostのunicode ()) を入力したいと思います。

4

1 に答える 1

2

ここでは a を使用しないでPositiveIntegerFieldください。ForeignKeytoを使用する必要がありますNewsPost

これにより、追加の労力なしで必要な 2 つのことが実行されます。

于 2013-09-28T14:54:42.343 に答える