How to fill dropdown on Django from database?

I am trying to fill up a dropdown on a form and the data is from database

forms.py

// ERROR: unsupported operand type(s) for +=: 'ModelChoiceIterator' and 'tuple'

    for x in MyModel.objects.values_list(
            'id',
            'name',
            named=True):
        self.fields['mymodel'].widget.choices += ((x.id, '%s - %s' % (x.id, x.name)),)

// I've tried, but it doesnt work

    for x in MyModel.objects.all():
        self.fields['mymodel'].widget.choices += ((x.id, '%s - %s' % (x.id, x.name)),)

What am I doing wrong?

Thank you

I am getting the date from database, the problem is, it retrieves an error when append to choices

SOLUTION:

simple_list = []    
for item in MyModel.objects.all():
    simple_list.append([item.id, f"{item.id} - {item.name}"])

self.fields['mymodel'].widget.choices = simple_list
Back to Top