开发者

Django forms error 'got multiple values for keyword argument 'choices''

Getting a strange error when defining my django forms. I get the error:

__init__() got multiple values for keyword argument 'choices'

This happens with both TestForm and SpeciesForm (quoted below); basically both forms with the 'choices' keyword argument. init() is never explicitly called, and the forms aren't even instantiated in the view yet. There's one ModelForm and one plain Form.

from django import forms as f
from orders.models import *

class TestForm(f.Form):
    species = f.ChoiceField('Species', choices=Specimen.SPECIES)
    tests = f.MultipleChoiceField('Test', choices=Test.TESTS, widget=f.CheckboxSelectMultiple())
    dna_extraction = f.CharField('DNA extraction', help_text='If sending pre-extracted DNA, we require at least 900 ng')

class SpeciesForm(f开发者_StackOverflow社区.ModelForm):
    TYPE_CHOICES = (
        ('blood', 'Blood'),
        ('dna', 'Extracted DNA'),
    )
    dam_provided = f.BooleanField('DAM', help_text='Is dam for this specimen included in sample shipment?')
    sample_type = f.ChoiceField('Type of sample', choices=TYPE_CHOICES)
    dna_concentration = f.CharField('DNA concentration', help_text='If sending extracted DNA, approximate concentration')

    class Meta:
        exclude = ['order']
        model = Specimen

Any help would be appreciated. Not sure why this is happening as the forms are pretty bare-bones.


http://code.djangoproject.com/browser/django/trunk/django/forms/fields.py#L647

647     def __init__(self, choices=(), required=True, widget=None, label=None,
648                  initial=None, help_text=None, *args, **kwargs):
649         super(ChoiceField, self).__init__(required=required, widget=widget, label=label,
650                                         initial=initial, help_text=help_text, *args, **kwargs)

use:

species = f.ChoiceField(label='Species', choices=Specimen.SPECIES)
tests = f.MultipleChoiceField(label='Test', choices=Test.TESTS, widget=f.CheckboxSelectMultiple())

and:

sample_type = f.ChoiceField(label='Type of sample', choices=TYPE_CHOICES)

This is assuming that your choices are valid. Not sure what Specimen.SPECIES and Test.TESTS are. Those should be iterable of two-tuples according to:

ChoiceField.choices

An iterable (e.g., a list or tuple) of 2-tuples to use as choices for this field. This argument accepts the same formats as the choices argument to a model field. See the model field reference documentation on choices for more details.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜