本文整理汇总了Python中models.Video.get_absolute_url方法的典型用法代码示例。如果您正苦于以下问题:Python Video.get_absolute_url方法的具体用法?Python Video.get_absolute_url怎么用?Python Video.get_absolute_url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Video
的用法示例。
在下文中一共展示了Video.get_absolute_url方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_or_edit_video
# 需要导入模块: from models import Video [as 别名]
# 或者: from models.Video import get_absolute_url [as 别名]
def create_or_edit_video(request, project_slug, video_slug=None):
project = get_object_or_404(Project, slug=project_slug)
if video_slug:
if not project.get_perms(request.user).get("has_member_perm", False):
request.user.message_set.create(message=NEED_MEMBER_PERM)
else:
video = get_object_or_404(Video, slug=video_slug, project=project)
if request.method == "POST" and "update" in request.POST:
video.sync_with_yt()
video.save()
request.user.message_set.create(message="Video infromation was updated.")
else:
request.user.message_set.create(message="Invalid data.")
return HttpResponseRedirect(video.get_absolute_url())
else:
action = "Add new Video"
form_class = forms.VideoCreationForm
video = Video(project=project, added_by=request.user)
if request.method == 'POST':
form = form_class(data=request.POST, instance=video)
form.project = project
if form.is_valid():
video = form.save()
return HttpResponseRedirect(video.get_absolute_url())
else:
form = form_class(instance=video)
return render_to_response('projects/create_or_edit_video.html', locals(),
context_instance=RequestContext(request))
示例2: test_model_get_absolute_url
# 需要导入模块: from models import Video [as 别名]
# 或者: from models.Video import get_absolute_url [as 别名]
def test_model_get_absolute_url(self):
video = Video(title="I is title", description="i is desc")
video.save()
self.assertEqual(
"/%s-%s/" % (video.id, video.slug), video.get_absolute_url())