source: music/views.py@ d7662b5

Last change on this file since d7662b5 was d7662b5, checked in by ManuelTrajcev <manueltrajcev7@…>, 5 weeks ago

init

  • Property mode set to 100644
File size: 1.2 KB
Line 
1from django.shortcuts import render
2import os
3import django
4from django.db import connection
5
6os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'MuiscOrganizationSystem.settings')
7django.setup()
8
9from music.models import *
10
11
12# Create your views here.
13
14def album_list(request):
15 heading = request.GET.get('model', 'All Albums')
16 data = Album.objects.values_list('title', flat=True)
17 return render(request, 'album_list.html', {'data': data, 'heading': heading})
18
19
20def track_list(request):
21 heading = request.GET.get('model', 'All Tracks')
22 data = Track.objects.values_list('name', flat=True)
23 return render(request, 'album_list.html', {'data': data, 'heading': heading})
24
25
26def tracks_count_per_genre(request):
27 with connection.cursor() as cursor:
28 cursor.execute("SELECT * FROM track_count_per_genre;")
29 rows = cursor.fetchall()
30
31 data = [{'genre': row[0], 'count': row[1]} for row in rows]
32 print(data)
33
34 return render(request, 'track_count_per_genre.html', {'data': data})
35
36
37def artist_list(request):
38 heading = request.GET.get('model', 'All Artists')
39 data = Artist.objects.values_list('name', flat=True)
40 print(data)
41 return render(request, 'album_list.html', {'data': data, 'heading': heading})
Note: See TracBrowser for help on using the repository browser.