Exemple #1
0
def create_music(request):
    form = MusicForm(request.POST or None)

    if form.is_valid():
        form.save()
        return redirect('list_musics')

    return render(request, 'music/music_form.html', {'form': form})
Exemple #2
0
 def post(self, request, *args, **kwargs):
     form = MusicForm(request.POST)
     if form.is_valid():
         form.save()
         messages.add_message(request, messages.INFO, 'Musikønske gemt.')
     else:
         messages.add_message(request, messages.ERROR, 'Musikønske IKKE gemt.')
     return redirect('music')
Exemple #3
0
def update_music(request, id):
    music = Music.objects.get(id=id)
    form = MusicForm(request.POST or None, instance=music)

    if form.is_valid():
        form.save()
        return redirect('list_musics')

    return render(request, 'music/music_form.html', {'form': form, 'music': music})