Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

205
Views
Las opciones de Django Dynamics ChoiceFields de las API generan ValueError

Encontré la respuesta en este ¿Cómo establecer opciones en dinámica con el campo de elección de Django?
maersu post tiene un alto voto en mi pregunta.

La salida de get_branch() es ["first_branch", "second_branch"]

django==1.11
python 3.6.0

forms.py

 class FactoryPOSForm(forms.ModelForm): branch_name = forms.ChoiceField(choices=['aa', 'bb']) class Meta: model = FactoryPOS fields = [ 'branch_name', 'dealer_name', 'shop_name', 'factory', ] def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.fields['branch_name'].choices = get_branches()

Error:

 File "/Users/el/.pyenv/versions/eneos-factory/lib/python3.6/site-packages/django/forms/boundfield.py", line 250, in build_widget_attrs if widget.use_required_attribute(self.initial) and self.field.required and self.form.use_required_attribute: File "/Users/el/.pyenv/versions/eneos-factory/lib/python3.6/site-packages/django/forms/widgets.py", line 690, in use_required_attribute return use_required_attribute and first_choice is not None and self._choice_has_empty_value(first_choice) File "/Users/el/.pyenv/versions/eneos-factory/lib/python3.6/site-packages/django/forms/widgets.py", line 673, in _choice_has_empty_value value, _ = choice ValueError: too many values to unpack (expected 2) [22/Apr/2017 16:47:04] ERROR [django.server:124] "GET /admin/factories_pos/factorypos/add/ HTTP/1.1" 500 445135

¿Dónde estoy extraño algo?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Desde doc, las opciones deben ser

Un iterable (p. ej., una lista o tupla) que consta de iterables de exactamente dos elementos (p. ej. [(A, B), (A, B) ...]) para usar como opciones para este campo. Si se proporciona, el widget de formulario predeterminado será un cuadro de selección con estas opciones en lugar del campo de texto estándar

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!