python - Django ModelChoiceField returning index. Want to get object at that position -


i have webpage can add new computer/ip database, or choose added dropdown list. works fine, except after user selecting item list index of it, , not name. how can name? trying access queryset vector seen here, typeerror.

views.py:

d = dropdownlist(request.post or none)     if d.is_valid():         c = request.post.get('current')         return httpresponse(d.qs[c-1]) 

models.py:

class dropdownlist(forms.form):     qs = computer.objects.all().order_by('name')     current = forms.modelchoicefield(qs, widget=forms.select(attrs={"onchange":'submit()'}))      class computer(models.model):     name = models.charfield(max_length=200, default='')     ip = models.charfield(max_length=200, default='')     def __unicode__(self):         return self.name 

home.html:

<form method="post">     {{ current }} </form> 

the whole point of using form takes care of validation , data conversion, in view should data form, not post itself.

if d.is_valid():     c = d.cleaned_data['current'] 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -