T
T
tanyaa2017-05-08 15:37:57
Django
tanyaa, 2017-05-08 15:37:57

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:
c7bd08eafc6a48c6a62cc82b511b0324.png

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})

Can you please tell me what needs to be changed so that the parameter values ​​from the ListOfParameters model and the operator values ​​from ListOfOperators are displayed in the drop-down list?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Kitaev, 2017-05-08
@tanyaa

Override __str__ method

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question