本文整理匯總了Python中models.Album.artist方法的典型用法代碼示例。如果您正苦於以下問題:Python Album.artist方法的具體用法?Python Album.artist怎麽用?Python Album.artist使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類models.Album
的用法示例。
在下文中一共展示了Album.artist方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: album
# 需要導入模塊: from models import Album [as 別名]
# 或者: from models.Album import artist [as 別名]
def album(request, album_id = None):
if album_id is not None:
album = request.db_session.query(Album).get(album_id)
else:
album = Album()
if request.method == 'POST':
if 'cancel' in request.POST:
return redirect('index')
form = AlbumForm(request.POST)
if form.is_valid():
# hydrate album object
album.title = form.cleaned_data['title']
album.artist = form.cleaned_data['artist']
# save it
request.db_session.add(album)
request.db_session.commit()
# show flash message to confirm update is OK
messages.success(request, "Album saved successfully")
# redirect to list of albums
return redirect('index')
elif album_id is not None:
form = AlbumForm(album.__dict__)
else:
form = AlbumForm()
return render(request, "album.html", {'form': form, 'album_id': album_id})