Jul 252009

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.

Posted by weboom at 1:30 pm Tagged with: , , , , ,
Jul 252009

Django query consists of
1. field name
2. lookup operator
separated by double underscores.
E.g.,
name__icontains
in
Card.objects.filter(name__icontains=query)

Posted by weboom at 12:57 pm Tagged with: ,
Jul 252009

Card.objects.filter(name__icontains=query)
i
means the operator performs a case-insenstive lookup.
(so hello would match both hello and Hello)

Posted by weboom at 12:55 pm Tagged with: , ,
Jul 252009

Django data model has an attribute objects
that can be used to perform queries on that model.
E.g.,
Card.objects.all()
Card.objects.filter(name__icontains=query)
etc.
This will provide a list of Card objects that matched the query (whose name contains query).

Posted by weboom at 12:51 pm Tagged with: ,
Switch to our mobile site
Top Footer