python - 限制某些用户添加新标签,django-taggit?

标签 python django django-taggit

我对 django 框架很陌生,我正在从头开始创建一个博客应用程序,并且我正在集成 django-taggit 来标记文章。我想要实现的是,我希望只有某些用户能够添加新标签,而其余用户只能使用现有标签。它类似于 stackoverflow 的实现,它允许具有一定声誉的用户添加新标签。

我如何实现这个目标?

最佳答案

你可以做几件事。首先我肯定会实现 UserProfile某种模型,即具有 reputation 属性,然后您有很多选项来完成您的任务,即

使用@user_passes_test装饰器,您可以在其中创建自己的函数以传递给装饰器。

def at_least_fifty_rep(user): 
    my_profile = ... # get the user profile
    return my_profile.reputation > 50

@user_passes_test(at_least_fifty_rep)
def my_custom_view(request):
    ...

或者,您也可以在模板中实现控件。

关于python - 限制某些用户添加新标签,django-taggit?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24566766/

相关文章:

python - 在Python中搜索连续字符串的匹配项

python:从 couchdb 端点获取 npm 包数据

django - 如何覆盖django静态文件开发服务器?

python - django-taggit:使标签在管理员中不需要

django-taggit 从查询集中创建 tagcloud

javascript - 使用请求登录到具有 javascript 登录表单的网站

python - 为什么这段 Haskell 代码这么慢?

python - 应用程序尚未准备好,升级到 Django 1.9,然后升级到 2.0

python - 如何构建依赖于另一个模型的表单集?

django - 如何过滤django-taggit top标签