javascript - Values of a dictionary in a dropdown -


my models.py follows:

class sellermarketplaces(models.model): id = models.integerfield(db_column='id',primary_key=true)  # field name made lowercase. seller_id = models.foreignkey('sellerdetails',db_column='seller_id')  # field name made lowercase. mk_id = models.foreignkey('marketplace',db_column='mk_id')  # field name made lowercase. username = models.charfield(db_column='username', max_length=100, blank=true, null=true)  

i have following code in views

def marketplaces(request):     seller = request.get.get('seller', '')   allmarketplaces = sellermarketplaces.objects.filter(seller_id = seller).values('mk_id__marketplace')   in range(len(allmarketplaces)):     print allmarketplaces[i]['mk_id__marketplace']   return render_to_response(request,'soumi1.html',{'marketplaces':marketplaces}) 

i getting values (flipkart & snapdeal) print allmarketplaces[i]['mk_id__marketplaces] line, return giving me 500 error.

my html file is:

        <select  name="marketplace" id="txthint" size="1" required>       <option value="">select marketplace</option>         {% if marketplaces.count > 0 %}           {% marketplace in marketplaces %}             <option value = {{ marketplace.id }}>{{ marketplace.marketplace }} </option>           }         {% endfor %}         {% endif %} 

the javascript used is:

  function showuser(str) {   if (str=="") {    document.getelementbyid("txthint").innerhtml="";    return;    }   if (window.xmlhttprequest) {   xmlhttp=new xmlhttprequest();   }   xmlhttp.onreadystatechange=function() {    if (xmlhttp.readystate==4 && xmlhttp.status==200) {   document.getelementbyid("txthint").innerhtml=xmlhttp.responsetext;   }   }   xmlhttp.open("get",'/marketplaces?seller='+username['value']);   xmlhttp.send();    } 

this line causing trouble:

return render_to_response(request,'soumi1.html',{'marketplaces':marketplaces}) 

you returning marketplaces view called marketplaces.


taking guess i'd want return list of marketplaces.

you can in following way:

marketplaces_list = sellermarketplaces.objects.filter(seller_id=seller).values_list('mk_id__marketplace', flat=true)  return render_to_response(request,'soumi1.html',{'marketplaces':marketplaces_list}) 

Comments

Popular posts from this blog

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -