title: strange error in simple loop in django while getting data from db
body: <p>I am getting data from django models and showing data in template using a for loop but it is saying: <code>TypeError at /jobs/
  __init__() takes exactly 1 argument (8 given)</code></p>
  
  <p>This is my view code that is to fetch data: </p>
  
  <pre><code>jobs_cities=City.objects.filter(job__isnull=False).distinct().annotate(jobs_count=models.Count('job')).order_by('jobs_count')[:6]
  </code></pre>
  
  <p>Then I am passing this data to template with following line of my view file:</p>
  
  <pre><code>return render_to_response('jobs/list.html', locals(),context_instance=RequestContext(request))
  </code></pre>
  
  <p>Then showing in template as:</p>
  
  <pre><code>{% for job_city in jobs_cities %}
    &lt;li&gt;&lt;a href="#"&gt;Jobs in {{job_city.name}} &lt;/a&gt;&lt;/li&gt;
   {% endfor %}
  </code></pre>
  
  <p>Stacktrace:</p>
  
  <pre><code>Environment:
  
  
  Request Method: GET
  Request URL: http://localhost:8000/jobs/
  
  Django Version: 1.4.1
  Python Version: 2.6.5
  Installed Applications:
  ('django.contrib.auth',
   'django.contrib.contenttypes',
   'django.contrib.sessions',
   'django.contrib.sites',
   'django.contrib.messages',
   'django.contrib.staticfiles',
   'jobs')
  Installed Middleware:
  ('django.middleware.common.CommonMiddleware',
   'django.contrib.sessions.middleware.SessionMiddleware',
   'django.middleware.csrf.CsrfViewMiddleware',
   'django.contrib.auth.middleware.AuthenticationMiddleware',
   'django.contrib.messages.middleware.MessageMiddleware')
  
  
  Template error:
  In template /media/../templates/jobs/list.html, error at line 93
     __init__() takes exactly 1 argument (8 given)
     83 : &lt;div class="clear"&gt;&lt;/div&gt;
  
  
     84 :   
  
  
     85 :   &lt;/div&gt;&lt;!--float_left--&gt;
  
  
     86 :   
  
  
     87 :   &lt;div class="float_right"&gt;
  
  
     88 :   &lt;div class="post_btn"&gt;&lt;a href="#"&gt;&lt;img src="{{STATIC_URL}}images/post_btn.gif" border="none" alt=""&gt;&lt;br&gt;&lt;img src="{{STATIC_URL}}images/ffree_text.gif"&gt;&lt;/a&gt;&lt;/div&gt;&lt;!--post_btn--&gt;
  
  
     89 :   &lt;div class="create_prfoile_btn"&gt;&lt;a href="#"&gt;&lt;img src="{{STATIC_URL}}images/banner.gif" alt="" border="none"&gt;&lt;/a&gt;&lt;/div&gt;&lt;!---create_prfoile_btn--&gt;
  
  
     90 :   &lt;div class="clear"&gt;&lt;/div&gt;
  
  
     91 :   &lt;div class="featured_jobs"&gt;
  
  
     92 :   &lt;ul&gt;
  
  
     93 :      {% for job_city in jobs_cities %} 
  
  
     94 :   &lt;li&gt;&lt;a href="#"&gt;Jobs in {{job_city.name}} &lt;/a&gt;&lt;/li&gt;
  
  
     95 :     {% endfor %}
  
  
     96 :   &lt;/ul&gt;
  
  
     97 :   
  
  
     98 :   &lt;/div&gt;&lt;!--featured_jobs--&gt;
  
  
     99 :   
  
  
     100 :   &lt;/div&gt;&lt;!--float_right--&gt;
  
  
     101 :   
  
  
     102 :   
  
  
     103 :   &lt;div class="clear"&gt;&lt;/div&gt;
  
  
  Traceback:
  File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py" in get_response
    111.                         response = callback(request, *callback_args, **callback_kwargs)
  File "/media/Local Disk/programming/django_projects/kaasib/jobs/views.py" in list
    38.     return render_to_response('jobs/list.html', locals(),context_instance=RequestContext(request))
  File "/usr/local/lib/python2.6/dist-packages/django/shortcuts/__init__.py" in render_to_response
    20.     return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
  File "/usr/local/lib/python2.6/dist-packages/django/template/loader.py" in render_to_string
    176.         return t.render(context_instance)
  File "/usr/local/lib/python2.6/dist-packages/django/template/base.py" in render
    140.             return self._render(context)
  File "/usr/local/lib/python2.6/dist-packages/django/template/base.py" in _render
    134.         return self.nodelist.render(context)
  File "/usr/local/lib/python2.6/dist-packages/django/template/base.py" in render
    823.                 bit = self.render_node(node, context)
  File "/usr/local/lib/python2.6/dist-packages/django/template/debug.py" in render_node
    74.             return node.render(context)
  File "/usr/local/lib/python2.6/dist-packages/django/template/loader_tags.py" in render
    123.         return compiled_parent._render(context)
  File "/usr/local/lib/python2.6/dist-packages/django/template/base.py" in _render
    134.         return self.nodelist.render(context)
  File "/usr/local/lib/python2.6/dist-packages/django/template/base.py" in render
    823.                 bit = self.render_node(node, context)
  File "/usr/local/lib/python2.6/dist-packages/django/template/debug.py" in render_node
    74.             return node.render(context)
  File "/usr/local/lib/python2.6/dist-packages/django/template/loader_tags.py" in render
    62.             result = block.nodelist.render(context)
  File "/usr/local/lib/python2.6/dist-packages/django/template/base.py" in render
    823.                 bit = self.render_node(node, context)
  File "/usr/local/lib/python2.6/dist-packages/django/template/debug.py" in render_node
    74.             return node.render(context)
  File "/usr/local/lib/python2.6/dist-packages/django/template/defaulttags.py" in render
    145.         len_values = len(values)
  File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py" in __len__
    85.                 self._result_cache = list(self.iterator())
  File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py" in iterator
    301.                     obj = model(*row[index_start:aggregate_start])
  
  Exception Type: TypeError at /jobs/
  Exception Value: __init__() takes exactly 1 argument (8 given)
  </code></pre>
  
  <p>I also looked at debugging code and it shows that jobs_cities is empty list, so I want to know that what I am actually doing wrong? </p>
  
  <p>thanks in advance guys.</p>