2011-02-09 19 views
1

私はManyToManyRawIdWidgetに基づいて自分のウィジェットを作成しています。Django、ManyToManyFieldをオーバーライドします。

しかし、すぐに私は私のModelAdminの中で次のことを試してくださいよう:

formfield_overrides = { 
    ManyToManyField: {'widget': ManyToManyRawIdWidget}, 
} 

それは私に

__init__() takes exactly 2 arguments (1 given) 

を促します、私は何か、おそらく関係でrel引数を満たすのに必要な考え出しモデル(Tagモデル)

しかし、私はTemplateSyntaxErrorを実行します:

Caught AttributeError while rendering: type object 'Tag' has no attribute 'to' 

ここで私は見落としがあります。誰かが私を助けてくれますか?

答えて

0

はちょうどあなたがdocumentation for formfield_overridesでこの警告を留意確認する:

Warning

If you want to use a custom widget with a relation field (i.e. ForeignKey or ManyToManyField), make sure you haven't included that field's name in raw_id_fields or radio_fields.

formfield_overrides won't let you change the widget on relation fields that have raw_id_fields or radio_fields set. That's because raw_id_fields and radio_fields imply custom widgets of their own.

私はManyToManyRawIdWidgetを認識していないんだけど、その名前から判断する私はraw_id_fieldsが、この場合に設定されるかもしれないと仮定しますか?それはなぜ働いていないのかもしれない。

+0

いいえ、私はその警告に出くわしました。したがって、raw_id_fieldsからフィールドを慎重に削除しました。それと運がない:( – Kasper

関連する問題