0

I want to show manytomany field value into a single input textbox in django template. My output is ABC /n Abc /n BVC /n

i want like ABC ,Abc,BVC

my code sample is this

    <div class='col-sm-8'>
{% for car in cars %}<br/>
      <input type='text' class='form-control' name='cars' placeholder='Select cars' value= {{car}}> 
{% endfor %}
      </div>

I want to show the output in Textbox field

1 Answer 1

0

You can do it:

from python: (views.py)

...
data_input = ', '.join([car for car in cars])
...

and in your template:

  <div class='col-sm-8'>
     <input type='text' class='form-control' name='cars' placeholder='Select cars' value= "{{ data_input }}"> 
  </div>
2
  • it shows me a error 'ManyRelatedManager' object is not iterable for views file
    – vikrant
    Sep 29, 2016 at 15:59
  • remember that car would be queryset, so... do it... cars = YourModelCar.ManyToManyRelation.all() to iterate.. Sep 29, 2016 at 16:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.