python - Cannot resole keyword 'carmodel' into field. Choices are: exterior_color, id, interior_color -


as want filter on foreign key, used carmodel __ in method dropdownlistsearch() of views.py. when run code, tells must field. don't understand part. why error. , using django 1.6.5.

models.py

from django.db import models class carinfo(models.model):0     vin_number = models.charfield(max_length = 17)     model = models.foreignkey(carmodel)     timestamp = models.datetimefield(auto_now_add = true, auto_now = false)     updated = models.datetimefield(auto_now_add = false, auto_now = true)     def __unicode__(self):         return self.vin_number      class carmodel(models.model):         model = models.charfield(max_length = 60)         def __unicode__(self):             return self.model 

views.py

def dropdownsearch(request):     try:         q = request.get.get('q')     except:         q = none      if q:         cars = carinfo.objects.filter(carmodel__model__contains=q)         template ='productions/resultstwo.html'     else:         template = 'prodcutions/cars.html'     context = {}      return render(request,template,context) 

cars.html

<form action="/cars/s/" method="get">                             <select name="q">     {% info in modelinfos %}         <option value="{{info.model}}">{{info.model}}</option>                                      {% endfor %}     </select>   </form> 

you filtering on forward relationship, use actual field have defined, model.

carinfo.objects.filter(model__model__contains=q) 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -