I thought I had it figured out but now I'm missing something.
First I have a QuerySet, records
records = Record.objects.all()
Now I want to make this into a list of one of the columns of the table, columnA
alist = records.values_list('columnA')
And then I want to pass this list in as a parameter to a custom form.
FilterForm(alist)
Here's my form
class FilterForm(forms.Form,list):
numbers = forms.ChoiceField(list)
but keep getting an error that 'type' object is not iterable. I'm not sure the problem has to do with the passing of the list because when I try and run this code in the shell, I get the error message when just importing the FilterForm
EDIT: I changed my FilterForm so now it looks like this.
class FilterForm(forms.Form):
def __init__(self,numbers):
number = forms.ChoiceField(numbers)
so now I think it's more evident what I'm trying to do, pass in a list to the FilterForm. However when I render my template and pass the form, no form field shows up. No error message though
EDIT EDIT: Also tried this, saw it online
class FilterForm(forms.Form):
number = forms.ChoiceField()
def __init__(self,numbers):
super(FilterForm,self).__init__()
self.fields['number'].choices=numbers
but error:
Exception Type: TemplateSyntaxError
Exception Value:
Caught ValueError while rendering: need more than 1 value to unpack