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.
Jul 252009
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)
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)
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).
