Use

objects.filter

———

e.g.,

>>>Card.objects.filter(name=’Hot Pot’)

>>>Card.objects.filter(name=’Hot Pot’, city=’San Diego’)

>>>Card.objects.filter(name_contains=’Hot’)

[<Card: Hot Pot>]

Note that here filter() returned a

QuerySet

which is like a list.

{{card.body|safe}}

Django template automatically “escapes” the contents of variables to prevent cross-site scripting attacks.

The safe filter lets you tell Django that you trust a variable and it doesn’t need a escaping.

other example of filter

{{card.body_html|truncatedwords_html:”50″|safe}}

{{card.pub_date|date:”F j, Y”}}

keyword_results=Card.objects.filter(searchkeyword__keyword__in=query.split()).distinct()

if keyword_results.count() == 1:

return HttpResponsRedirect(keyword_results[0].get_absolute_url())

————

results of database queries is special object called

QuerySet

is the class Django uses to represent a database query.

Each QuerySet has methods such as,

filter()

distinct()

count()

etc.

© 2011 Web Oom Suffusion theme by Sayontan Sinha
Switch to our mobile site
Top Footer