本文整理汇总了Python中models.Item.favorites方法的典型用法代码示例。如果您正苦于以下问题:Python Item.favorites方法的具体用法?Python Item.favorites怎么用?Python Item.favorites使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Item
的用法示例。
在下文中一共展示了Item.favorites方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: bookmark_reply
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import favorites [as 别名]
def bookmark_reply(request, id):
bookmark = get_object_or_404(Bookmark, id=id)
if bookmark.item is None:
try:
item = Item.objects.get(url=bookmark.url)
except Item.DoesNotExist:
item = Item(title=get_bookmark_title(bookmark.url), url=bookmark.url, favorites=1)
item.save()
bookmark.item = item
bookmark.save()
item.favorites = item.bookmark_set.count()
item.save()
else:
item = bookmark.item
return redirect('item_reply', id=item.id)
示例2: addurl
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import favorites [as 别名]
def addurl(request):
if request.session.get('id', None) is None:
request.session['redirect_url'] = request.GET.get('url', None)
return redirect('signin')
url = current_url(request.GET.get('url', None).encode('utf-8'))
title = get_bookmark_title(url)
user = get_object_or_404(User, id=request.session.get('id', None))
# 添加到Item表
try:
item = Item.objects.get(url=url)
try:
# 如果书签已存在 直接跳到编辑页面
bookmark = Bookmark.objects.get(url=item.url, user=user)
# 如果书签通过导入文件添加 不走item表 所以bookmark表item_id为0
if bookmark.item_id is None:
bookmark.item = item
bookmark.save()
# 更新item的书签数量
item.favorites = item.bookmark_set.count()
item.save()
return redirect('bookmark_edit', id=bookmark.id)
except Bookmark.DoesNotExist:
pass
except Item.DoesNotExist:
item = Item(url=url.encode('utf-8'), title=title.encode('utf-8'))
item.save()
try:
# 如果书签已存在 直接跳到编辑页面
bookmark = Bookmark.objects.get(url=item.url, user=user)
# 如果书签通过导入文件添加 不走item表 所以bookmark表item_id为0
if bookmark.item_id is None:
bookmark.item = item
bookmark.save()
# 更新item的书签数量
item.favorites = item.bookmark_set.count()
item.save()
return redirect('bookmark_edit', id=bookmark.id)
except Bookmark.DoesNotExist:
pass
form = BookmarkForm(initial={'title':title})
lists = user.list_set.all()
return render(request, 'bookmark/new.html', {'form': form, 'lists': lists, 'item': item})
示例3: edit
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import favorites [as 别名]
def edit(request, id):
bookmark = get_object_or_404(Bookmark, id=id)
if bookmark.user.id != request.session.get('id', None):
raise Http404
if bookmark.item is None:
try:
item = Item.objects.get(url=bookmark.url)
except Exception, e:
title = get_bookmark_title(bookmark.url)
item = Item(url=bookmark.url, title=title.encode('utf-8'), favorites=1)
item.save()
bookmark.item = item
bookmark.save()
item.favorites = item.bookmark_set.count()
item.save()