def album_form(request): add_album = forms.AlbumForm() diction = {'add_album': add_album} if request.method == 'POST': add_album = forms.AlbumForm(request.POST) if add_album.is_valid(): add_album.save(commit=True) return index(request) return render(request, 'First_app/album_form.html', context=diction)
def album_form(request): form = forms.AlbumForm() if request.method == 'POST': form = forms.AlbumForm(request.POST) if form.is_valid(): form.save(commit=True) return index(request) diction = {'title': "Add Album", 'album_form': form} return render(request, 'first_app/album_form.html', context=diction)
def album_form(request): mform = forms.AlbumForm() #Creating a Musician form object if request.method == "POST": mform = forms.AlbumForm(request.POST) if mform.is_valid(): mform.save(commit=True) return first(request) dic = {'title': "Add Album", 'album_form': mform} return render(request, 'first_app/album_form.html', context=dic)
def edit_album(request, album_id): info_album = Album.objects.get(pk=album_id) form = forms.AlbumForm(instance=info_album) diction = {} if request.method == 'POST': form = forms.AlbumForm(request.POST, instance=info_album) if form.is_valid(): form.save(commit=True) diction.update({'success_text': 'SuccessFully Updated'}) diction.update({'form1': form}) diction.update({'album_id': album_id}) return render(request, 'First_app/edit_album.html', context=diction)
def edit_album(request, album_id): album_info = Album.objects.get(pk=album_id) form = forms.AlbumForm(instance=album_info) diction = {} if request.method == 'POST': form = forms.AlbumForm(request.POST, instance=album_info) if form.is_valid(): form.save(commit=True) diction.update({'success_key': 'Album successfully Updated'}) diction.update({'edit_album': form}) diction.update({'album_id': album_id}) return render(request, 'first_app/edit_album.html', context=diction)
def editAlbum(request, album_id): album_info = Album.objects.get(pk=album_id) album_form = forms.AlbumForm(instance=album_info) diction={'title': "Edit Album",} if request.method == "POST": album_form = forms.AlbumForm(request.POST, instance=album_info) if album_form.is_valid(): album_form.save(commit=True) diction.update({ 'success_text':'Successfully Updated' }) # return albumList(request, album_info.artist_id) diction.update({ 'album_form':album_form, 'album_id':album_id }) return render(request, 'first_app/edit_album.html', context=diction)