models.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:dream_blog 作者: fanlion 项目源码 文件源码
def add_view_permissions(sender, **kwargs):
    """
    This syncdb hooks takes care of adding a view permission too all our
    content types.
    """
    # for each of our content types
    for content_type in ContentType.objects.all():
        # build our permission slug
        codename = "view_%s" % content_type.model

        # if it doesn't exist..
        if not Permission.objects.filter(content_type=content_type, codename=codename):
            # add it
            Permission.objects.create(content_type=content_type,
                                      codename=codename,
                                      name="Can view %s" % content_type.name)
            # print "Added view permission for %s" % content_type.name


# check for all our view permissions after a syncdb
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号