2 ms·
the filter gives you a tangible "query" to work with so that you can continually add criteria as you build your query. for example, i can say: grants = Gran
by mattdennewitz 18y ago
the filter gives you a tangible "query" to work with so that you can continually add criteria as you build your query.
for example, i can say:
grants = Grants.objects.filter(is_approved=True)
to get all of the Grants to an Organization, and then
if not request.user.is_superuser:
grants = grant.filter(sponsoring_trustee=request.user)
to filter out grants that only pertain to a certain user.
"grants" isnt evaluated (queried) until its iterated over or otherwise called (print, for example), so i can keep building what i want as i go without having several sql calls or managing building a query via string concatenation. personally, i've always found django's orm to feel natural.