Created
August 2, 2014 19:31
-
-
Save ybigus/aa4504a501e49144bbd2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.shortcuts import render | |
from django.http import HttpResponse, HttpRequest | |
from main.models import Track | |
from django.db.models import Q | |
def index(request): | |
if request.method == 'POST': | |
term = request.POST["term"] | |
tracks = Track.objects.filter(Q(name__icontains=term)| Q(artist__icontains=term)).order_by('-rate')[:10] | |
context = {'tracks': tracks, 'term': term} | |
else: | |
most_rated_tracks = Track.objects.all().order_by('-rate')[:10] | |
context = {'tracks': most_rated_tracks} | |
return render(request, 'index.html', context) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment