Example #1
0
def addSong(request):
    if request.method == 'POST':
        form = SongForm(request.POST)
        if form.is_valid():
            # Process form data from form.cleaned_data
            newTrackNum = len(
                Song.objects.filter(
                    playlistID__exact=form.cleaned_data['playlistID']))
            currentSong = Song()
            currentSong.songName = form.cleaned_data['songName']
            currentSong.songUrl = form.cleaned_data['songUrl']
            currentSong.playlistID = form.cleaned_data['playlistID']
            currentSong.playlistPosition = newTrackNum
            currentSong.save()
            pl_id = currentSong.playlistID
            return HttpResponseRedirect("/songs/%d&tracknum=%d" %
                                        (pl_id, newTrackNum))
    else:
        form = SongForm()

    return render(request, 'songs/addSong.html', {'form': form})