简体   繁体   English

Django验证用户从管理面板发送的内容

[英]Django validate what user sends from admin panel

I am kind of new to Django, and i am trying to make sort of a news website where users can submit articles(with an account) but the admin needs to check them before they can be posted. 我是Django的新手,我正在尝试建立一个新闻网站,用户可以在该网站上提交文章(使用帐户),但管理员需要先对其进行检查,然后才能将其发布。 Is that possible? 那可能吗?

Yes, it is. 是的。

The simplest approach would be creating simple flag in model let's say a Boolean field named verified , which by default would be False. 最简单的方法是在模型中创建简单的标记,假设一个布尔字段名为verified ,默认情况下为False。 You could add permissions. 您可以添加权限。 So in the end you could overwrite a function in your admin form, and show the field for superuser only. 因此,最终您可以覆盖您的admin表单中的函数,并仅显示超级用户字段。

class MyUserAdmin(admin.ModelAdmin):

def get_form(self, request, obj=None, **kwargs):

        self.exclude = []
        if not request.user.is_superuser:
            self.exclude.append('Permissions') #here!
        return super(MyUserAdmin, self).get_form(request, obj, **kwargs)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM