本文整理汇总了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})