Commit e02d509f authored by Brian Guadalupe's avatar Brian Guadalupe

Create app `search`

parent 0ba13f5c
from django.contrib import admin
# Register your models here.
from django.apps import AppConfig
class SearchConfig(AppConfig):
name = 'search'
from django.db import models
from django.apps import AppConfig
class MusicBrainzHook(AppConfig):
name = 'Musicbrainzhook'
verbose_name = name
def ready(self):
print("Self called")
def custom():
print("print called")
\ No newline at end of file
from django.test import TestCase
# Create your tests here.
from django.shortcuts import render, redirect, get_object_or_404
from core.models import *
from search.musicbrainzhook import *
def search(request):
type = request.GET.get('searchtype', '')
term = request.GET.get('search', '')
artistAlbums = Album.objects.filter(artist__name__contains = term)
if type == 'song':
results = Song.objects.filter(song_name__contains = term)
elif type == 'album':
results = Album.objects.filter(album_name__contains = term)
elif type == 'artist':
results = Artist.objects.filter(name__contains = term)
context = {
'type': type,
'term': term,
'results': results,
'albums': artistAlbums,
}
return render(request, 'search.html', context)
def artist_profile(request, identifier):
result = Artist.objects.filter(id = identifier)
albums = Album.objects.filter(artist = identifier)
return render(request, 'artist.html', {'result': result[0], 'albums': albums})
def album_profile(request, identifier):
result = Album.objects.filter(id = identifier)
artist_name = result[0].artist.name
songs = Song.objects.filter(album = identifier)
return render(request, 'album.html', {'result':result[0], 'songs': songs, 'artist': artist_name})
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment