Use

update()

on QuerySet.

———–

e.g.,

>>>Card.objects.all().update(country=’USA’)

The update() method has a return value which is an integer that represents how many records changed.

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.

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