简体   繁体   中英

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. 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. You could add permissions. So in the end you could overwrite a function in your admin form, and show the field for superuser only.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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