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