2
votes

I try to use make a droplist from model.

USER_TYPE = {
'admin': "Admin",
'patient': "Patient",
'helper': "Helper",
'therapist': "Therapist",
}


class User(AbstractBaseUser):
    user_type = models.CharField(max_length=10, choices=USER_TYPE, default="patient")

However, I get this error:

ValueError: too many values to unpack (expected 2)

Thanks in advance!

2

2 Answers

3
votes

All you need is tuples instead of dictionary. Like :

YEAR_IN_SCHOOL_CHOICES = ( ('FR', 'Freshman'), ('SO', 'Sophomore'), ('JR', 'Junior'), ('SR', 'Senior'), )

1
votes
  1. You are using a CharField, but if you want a dropdown, you should be using a ChoiceField

  2. You are supplying USER_TYPE as a dictionary but

    choices

    Either an iterable (e.g., a list or tuple) of 2-tuples to use as choices for this field, or a callable that returns such an iterable. 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. If the argument is a callable, it is evaluated each time the field’s form is initialized. Defaults to an empty list. https://docs.djangoproject.com/en/1.11/ref/forms/fields/#django.forms.ChoiceField.choices

So try something like:

USER_TYPE = [
('admin', "Admin"),
('patient', "Patient"),
(..., ...),
]