форма

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
# -*- coding: utf-8 -*-
from django import forms
from agriculture.models import Economy
class SubtypeModelChoiceField(forms.ModelChoiceField):
def label_from_instance(self, obj):
return "%s" % obj.subtype
class RegionChoiceField(forms.ModelMultipleChoiceField):
def label_from_instance(self, obj):
return "%s" % obj.region
class DistrictChoiceField(forms.ModelChoiceField):
def label_from_instance(self, obj):
return "%s" % obj.district
class EconomyForm(forms.Form) :
subtype = SubtypeModelChoiceField(queryset=Economy.objects.all(),widget=forms.Select,label="Подтип")
# subtype = forms.ModelChoiceField(Economy.objects.all(),widget=forms.Select)
region = RegionChoiceField(queryset=Economy.objects.all(),empty_label=None,label="Область")