开发者

Accessing key field into Django Template

How can I access key field of model into django template开发者_StackOverflow?


**key** should be the name of the attribute you are expecting to find in the blockedsoftwares_list

So, assuming your blockedsoftwares_listcontain a list of key (then the choice of the variable name is not explicit), you want to check that the key field of the current software is not in the blocked software key list:

{% for software in softwares %}
   {% if software.key not in blockedsoftwareskeys %}
      {{ software.name }}<br />
      {{ software.version }}<br />
      {{ software.description }}<br />
   {% endif %}
{% endfor %}

Assuming this is the wanted behavior (please be more specific by editing your question), then why giving the whole query set to your template when django orm allows you to use filters in the view ?


There are 2 solutions:

  1. You should filter the data before passing it into view

  2. You can write additional function in model for retrieving the key if it`s not a field already

Can you explain exactly what is **__key__** ?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜