querying/filtering a list of data inside django template

189 Views Asked by At

how do i do a filter in a django template? lets say that i have a model like this

class Entity:
    attribute1
    attribute2

something like that now i have a form.py to submit data into my database

Class EntityForm:
    Class Meta:
        model=Entity

now in the template i have my form and in my view i have the contorller of my form

so when everything works fine i get all the data i wanted and now i have so many data that i submited that i want to search for just specific results, now i want to filter/query all the data throught my template, is this posible? how?

i was wondering if i should do something hard because im still learning, i wanted to do a

{% entity.objects.filter(atribute2='something') %}

but this doesnt work! any idea?

thanks!

1

There are 1 best solutions below

5
On BEST ANSWER

Why do you want to do that in your template? If the user submitted a search query, that goes to your view first, so that is the appropriate place to do the filter.

As is clearly documented, the template language is expressly restricted, so that you can't call functions with parameters.