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_list
contain 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:
You should filter the data before passing it into view
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__**
?
精彩评论