当前位置: 首页>>代码示例>>Python>>正文


Python Video.get_absolute_url方法代码示例

本文整理汇总了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))            
开发者ID:gdos,项目名称:pygame,代码行数:34,代码来源:views.py

示例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())
开发者ID:abdelhai,项目名称:godjango-site,代码行数:8,代码来源:tests.py


注:本文中的models.Video.get_absolute_url方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。