[Answer]-Django MultipleChoiceField choices of users throws error

1👍

✅

It’s because MultipleChoiceField.choices is expected to be a 2d Array effectively (https://docs.djangoproject.com/en/1.7/ref/forms/fields/#django.forms.ChoiceField.choices).

So you could do something like this:

team = [(u.pk, u.email) for u in User.objects.filter(groups__name=project.project_name)]

And that will return you a list continaing the combintation of

[('user1.pk', 'user1.email'), ('user2.pk', 'user2.email'),...]

which will be useable as the choices.

Leave a comment