Первый тупл это primary key (то бишь номер записи), второй - сгенерированный текст
views.py from django.http import HttpResponse, HttpRequest, HttpResponseRedirect from .models import * def n01_size_kss(request): if request.method == 'POST': form = KSS_Form(request.POST) context = {'form':form} if form.is_valid(): filtertype, context = n01_context_cleaned_data(form.cleaned_data) if filtertype != "none": geh_innen_choice = prepare_dictionary_form2(context) form1.fields['geh_innen'].choices = geh_innen_choice context = {'form':form1, **context} return render(request, 'af/size/01_kss_size2.html', context) else: context = {'form':KSS_Form()} return render(request, 'af/size/01_kss_size1.html', context) def prepare_dict_form_n01_01(context): baureihe_record1 = context['baureihe_record1'] filter_label = baureihe_record1.series.valuefg x_choice = afc_select_housing_innenteile.objects.filter(Q(series__valuefg__exact=filter_label)).order_by('price') geh_innen_choice = [] for i in x_choice: x = "Housing: " + i.mat_housing.descr x1 = (i.id, x) geh_innen_choice.append(x1) return geh_innen_choice
forms.py from django import forms from django.conf.urls.i18n import i18n_patterns class KSS_Form1(forms.Form): geh_innen = forms.ChoiceField(\ required=True, \ label=_("Specify material of the housing:"), \ disabled=False, \ )
В результате получаю ошибку
form.is_valid=FALSE
form.errors
Select a valid choice. 119 is not one of the available choices
Вот таким образом выглядит ХТМЛ код этого ChoiceField
<select name="mat_geh_innen" id="id_mat_geh_innen"> <option value="102">Housing: nodular cast iron || Internals: carbon steel || Element: coil type (Al/1.4571) </option> <option value="103">Housing: nodular cast iron || Internals: carbon steel || Element: welded type (1.4571)</option> <option value="107">Housing: nodular cast iron || Internals: stainless steel || Element: coil type (Al/1.4571)</option> <option value="104">Housing: nodular cast iron || Internals: carbon steel || Element: coil type (1.4571)</option> <option value="108">Housing: nodular cast iron || Internals: stainless steel || Element: welded type (1.4571)</option> <option value="109">Housing: nodular cast iron || Internals: stainless steel || Element: coil type (1.4571)</option> <option value="112">Housing: Stainless steel cast design || Internals: carbon steel || Element: coil type (Al/1.4571)</option> <option value="113">Housing: Stainless steel cast design || Internals: carbon steel || Element: welded type (1.4571)</option> <option value="117">Housing: Stainless steel cast design || Internals: stainless steel || Element: coil type (Al/1.4571)</option> <option value="114">Housing: Stainless steel cast design || Internals: carbon steel || Element: coil type (1.4571)</option> <option value="118">Housing: Stainless steel cast design || Internals: stainless steel || Element: welded type (1.4571)</option> <option value="119">Housing: Stainless steel cast design || Internals: stainless steel || Element: coil type (1.4571)</option> </select>