Trying to filter the contents of a ChoisceField

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
##CODE 1:
from models import City, Zone

class SearchForm1(forms.Form):
   cityf = forms.ModelChoiceField(queryset=City.objects.all(), empty_label="none")
   zonef = forms.ModelChoiceField(queryset=Zone.objects.all(), empty_label="none")
---------------------------------
##CODE 2:
class SearchForm1(forms.Form):
   cityf = forms.ModelChoiceField(queryset=City.objects.all(), empty_label="none")
   zonef = forms.ModelChoiceField(queryset=City.objects.get(name_city="cityf").zone_set.all(), empty_label="none")
---------------------------------
But I recive this
##ERROR:
Exception Type: DoesNotExist
Exception Value:

City matching query does not exist.

Exception Location:
/usr/local/lib/python2.6/dist-packages/django/db/models/query.py in
get, line 349
------------------------------------

More like this

  1. Updated Filter to resize a ImageField on demand by gmandx 3 years, 8 months ago
  2. debug info middleware by mzitnik 4 years, 9 months ago
  3. Localizing a ChoiceField by eRAZOR 4 years, 10 months ago
  4. tag: render form field by crucialfelix2 3 years, 6 months ago
  5. ForeignKey filterspec by luc_j 2 years, 8 months ago

Comments

(Forgotten your password?)