First, I am quite new with django... I am trying to add a dropdown menu of available distinct Users (by name and coming from my db "dynamically") in a form.
I am using django 2.2.6.
# MyCustomForm
class DetailedReportForm(forms.Form):
AVAILABLE_USERS = MyUserModel.objects.order_by().values_list('name').distinct()
selected_date = forms.DateTimeField(input_formats=['%d/%m/%Y'], required=True, widget=DateInput())
selected_user = forms.CharField(label="Select a user", widget=forms.Select(choices=AVAILABLE_USERS))
# MyModel
class MyUserModel(models.Model):
id = models.AutoField(db_column='Id', primary_key=True)
name = models.CharField(db_column='Name', unique=True, max_length=90)
...
def __str__(self):
return str(self.name)
The issue I am facing is my queryset is not working (not sure why) as it is giving me the following: not enough values to unpack (expected 2, got 1)
I tried to google it but still not very clear to me what this error message means.
Can someone please explain what this django error means so I can fix it and include the dropdown list in my form?