Answer the question
In order to leave comments, you need to log in
How to correctly display the data from the model in the dropdown list?
The dropdown list does not display values from the model, but simply indicates that these are queryset objects:
models.py:
class unit_case(models.Model):
user = models.ForeignKey('auth.User')
parameter = models.ForeignKey(ListOfParameters,default=0,to_field='parameter')
operator = models.ForeignKey(ListOfOperators,default=0,to_field='operator')
forms.py:
class unit_caseForm(forms.ModelForm):
class Meta:
model = unit_case
fields = ('parameter', 'operator')
views.py:
def utest_new(request):
if request.method == "POST":
form = unit_caseForm(request.POST)
if form.is_valid():
utest = form.save(commit=False)
utest.user = request.user
utest.save()
return redirect('utest_base.views.utest_new')
else:
form = unit_caseForm()
query_all = unit_case.objects.all().order_by('created_date').reverse()
return render(request, 'utest_base/utest_edit.html', {'form': form,'query_all':query_all})
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question