0

Neomodel のドキュメントで提供されている例に従って、フォームに選択肢を表示できません。

class Person(StructuredNode):
    SEXES = {'F': 'Female', 'M': 'Male', 'O': 'Other'}
    sex = StringProperty(required=True, choices=SEXES)

この例を使用すると、Django の実行時にエラーが発生します。

packages/django_neomodel/__init__.py", line 122, in get_choices
    for choice, __ in choices:
ValueError: not enough values to unpack (expected 2, got 1)

SEXES を変更し、'FF'、'MM' などを指定すると、サーバーを実行できますが、値は次のように表示されます。

<option value="F">F</option>
<option value="M">M</option>
<option value="O">O</option>

モデルで次のコードを使用しました。

COUNTRY_CODE1=[('AF', 'Afghanistan (+93)'), ('AL', 'Albania (+355)'), ('DZ', 'Algeria')]
...
ind_nationality = StringProperty(max_length=2,choices=COUNTRY_CODE1,label='Nationality')

これをブラウザに入力すると、次のように生成されます。

<option value="A">F</option>
<option value="A">L</option>
<option value="D">Z</option>

models.py

class Person(DjangoNode):
    uid_person = UniqueIdProperty()
    ind_name = StringProperty(max_length=100 , label='Enter your First Name')
    ind_last_name = StringProperty(max_length=100,null=True, label='Last Name')
    ind_nationality = StringProperty(max_length=2,choices=COUNTRY_CODE1,label='Nationality')

フォーム.py

class PersonRegForm (ModelForm):
    class Meta:
        model=Person
        fields = ['ind_name','ind_last_name', 'ind_nationality']
        widgets = {

            'ind_name' : forms.TextInput(attrs={'size':50}),
            'ind_last_name' : forms.TextInput(attrs={'size':50}),
            'ind_nationality' : forms.Select(),

        }
        app_label = 'reg'



class PersonRegView(generic.FormView):
    template_name='reg/personreg.html'
    form_class=PersonRegForm
    success_url = 'index'

次の結果を期待しています

<option value="AF"></option>
4

1 に答える 1