5 March

My query function

def search(request):
    q = Q(isbn=request.GET['isbn'])

    if request.GET['title']:
        q = q | Q(title__icontains=request.GET['title'])
    if request.GET['authors']:
        q = q | Q(authors__icontains=request.GET['authors'])
    if request.GET['course']:
        q = q | Q(course__title__icontains = request.GET['course'])

    # For courses, if we specify BOTH prefix and number, use Boolean AND.
    if request.GET['prefix'] and request.GET['number']:
        q = q | (Q(course__prefix__iexact = request.GET['prefix']) &
                 Q(course__number__iexact = request.GET['number']))
    elif request.GET['prefix']:
        q = q | Q(course__prefix__iexact = request.GET['prefix'])
    elif request.GET['number']:
        q = q | Q(course__number__iexact = request.GET['number'])

    results = Book.objects.filter(q).distinct()
    return render_to_response('search.html',
                              {'results': results, 'user': request.user})

Show two decimal points in prices

${{b.price|floatformat:2}}
comments powered by Disqus

 

©2012 Christopher League · some rights reserved · CC by-sa