Querying Many to many fields in django template

后端 未结 2 609
北海茫月
北海茫月 2020-12-08 23:39

This may not be relevant but just wanted to ask,

IF an object is passed from views to template and in the template will i be able to query many to many fields

<
2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-08 23:57

    In general, you can follow anything that's an attribute or a method call with no arguments through pathing in the django template system.

    For the view code above, something like

    {% for objs in obj_arr %}
    {% for answer in objs.answers.all %}
      {{ answer.someattribute }}
    {% endfor %}
    {% endfor %}
    

    should do what you're expecting.

    (I couldn't quite make out the specifics from your code sample, but hopefully this will illuminate what you can get into through the templates)

提交回复
热议问题