Finding 2 values if available in a list in a Django Template

A_K

I have the following list called `` :[(2, 'Flat Bench'), (1, 'Flat Bench'), (3, 'Flat Bench')]

I am trying to find if the b.order which is the first number and e.name which is the 2nd string is available from a django template. In my trial I made sure that b.order is equal to 2 and e.name is 'Flat Bench'.

Here is the django template:

  {% if b.order and e.name in all_logs %}
  available
  {% else%}
  not available
  {% endif %}

In my case there is no error, it is just always showing not available even if it is available.

I am not sure what change I should be doing to get this code to work.

Abdullah

Well, I would suggest to create custom tags as explained here: https://docs.djangoproject.com/en/4.1/howto/custom-template-tags/

Your custom function should look as follows:

my_custom_tags.py

from django import template

register = template.Library()


@register.simple_tag
def tuple_check(items, key, value):
    return (key, value) in items

Your template should have the following:

{% load my_custom_tags %}
...
some codes here
...

{% tuple_check your_list b.order e.name as item_check_result %}

{% if item_check_result %}
Available
{% else %}
Not Available
{% endif %}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Django - Show list datetime values in template

Django template: How to use values/values_list

Finding two smallest values in a list

Django Template: How to display the value of Foreign Key in a values_list

Obtaining top 2 max values from a list and finding its corresponding value from 2nd list

Comparing values in django template

unique values in django template

Finding values in a matrix from list of values in R

Django template : Need 2 values to unpack in for loop; got 8

display list in django template

Django Template extract list

Request object not available in template tags in Django 1.11

Django: Include template with constructed name if available

how to list available arguments in a jinja template

Django: template to list data from 2 models related each other

Filter 2D list with template tag in Django

Finding list of versions available in a Maven repository for a specific plugin?

Finding the most common Values in a list of ndarrays in Python

Finding a list of keys containing equal values in a dictionary

Excel Help for Finding List of Maximum Values

Finding a sublist in a list and sum its values

Finding values greater than * in a map list

Finding Min and Max Values in List Pattern in Python

Finding values in elements of a list greater than X

Finding nested list with identical values in Dictionaries [Python]

Slope Intercept Formula for Finding list of y values

Optimising Finding Closest Value in a List of Values

PYTHON: Finding the average of values of a nested list

Finding items in a list and then displaying back those values

TOP Ranking

  1. 1

    How can I create a column whose entries depend on the contents of a column in another table?

  2. 2

    pump.io port in URL

  3. 3

    How to display items using sessions

  4. 4

    BigQuery - concatenate ignoring NULL

  5. 5

    no applicable method for 'mutate_' applied to an object of class "c('integer', 'numeric')"

  6. 6

    How i extract text from a model dialog in selenium?

  7. 7

    x no applicable method for 'tbl_vars' applied to an object of class "c('double', 'numeric')"

  8. 8

    AirflowException: Celery command failed - The recorded hostname does not match this instance's hostname

  9. 9

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  10. 10

    Most efficient regex for checking if a string contains at least 3 alphanumeric characters

  11. 11

    using excel range find return Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))

  12. 12

    redirect your computer port to url

  13. 13

    Can't create database with Symfony 4.1 : could not find driver

  14. 14

    How to fix "Exception evaluating SpringEL expression" error after submitting a variable Spring/Thymeleaf

  15. 15

    A python function to get the maximum value of a specific column, given a string that represents a table in CSV format

  16. 16

    Double spacing in rmarkdown pdf

  17. 17

    Uploading Files on production server returns either CORS error or POST 400 Bad Request using Apollo-Graphql

  18. 18

    Android Kotlin Unit test failing with io.mockk.MockKException: no answer found for

  19. 19

    Change Model input_shape but got an : ValueError: Input 0 of layer dense_44 is incompatible with the layer

  20. 20

    Formik, Yup - How to check is Decimal number

  21. 21

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

HotTag

Archive