0

デフォルトでは、選択フィールドのオプションの数は 4 ですが、この数を増やすオプションはありますか? おそらく5または6に?

編集:

私のモデル -->

class Other(models.Model):
    txt = models.CharField(choices=CHOICES) #CHOICES is a dynamically generated list of tuples from a database query

    class Meta:
    db_table = 'my_table'
    ordering = ['txt']

class Main(models.Model):

    #Other fields..
    other = models.ManyToManyField(Other)

HTML -->

//I use the 'Main' model that is represented as 'form' in the html code

//....

{{ form.other.label }}<br>
{{ form.other }}

//rest of html....
4

1 に答える 1

1

choicesモデルフィールドは呼び出し可能にすることはできず、タプル/リストにする必要があります。フォームに対して一般的に行われているように、メソッドを介してオーバーライドすること__init__()は、モデルでは推奨されません。

モデルの再設計が必要になる場合があります。ForeignKey()モデルと関係がある選択肢に対して別のモデルを作成できますOther

選択肢の数について見たことがあるかもしれませんが、そのモデル クラスが初期化されたときに存在する選択肢の数です。

于 2013-09-07T05:50:49.757 に答える