1. <tfoot id='uKSkp'></tfoot>
        <bdo id='uKSkp'></bdo><ul id='uKSkp'></ul>

      1. <i id='uKSkp'><tr id='uKSkp'><dt id='uKSkp'><q id='uKSkp'><span id='uKSkp'><b id='uKSkp'><form id='uKSkp'><ins id='uKSkp'></ins><ul id='uKSkp'></ul><sub id='uKSkp'></sub></form><legend id='uKSkp'></legend><bdo id='uKSkp'><pre id='uKSkp'><center id='uKSkp'></center></pre></bdo></b><th id='uKSkp'></th></span></q></dt></tr></i><div id='uKSkp'><tfoot id='uKSkp'></tfoot><dl id='uKSkp'><fieldset id='uKSkp'></fieldset></dl></div>

        <small id='uKSkp'></small><noframes id='uKSkp'>

        <legend id='uKSkp'><style id='uKSkp'><dir id='uKSkp'><q id='uKSkp'></q></dir></style></legend>

        django - 使用 get_or_create 自动创建用户时设置用户权限

        django - set user permissions when user is automatically created using get_or_create(django - 使用 get_or_create 自动创建用户时设置用户权限)

          <legend id='sHI3A'><style id='sHI3A'><dir id='sHI3A'><q id='sHI3A'></q></dir></style></legend>
        • <i id='sHI3A'><tr id='sHI3A'><dt id='sHI3A'><q id='sHI3A'><span id='sHI3A'><b id='sHI3A'><form id='sHI3A'><ins id='sHI3A'></ins><ul id='sHI3A'></ul><sub id='sHI3A'></sub></form><legend id='sHI3A'></legend><bdo id='sHI3A'><pre id='sHI3A'><center id='sHI3A'></center></pre></bdo></b><th id='sHI3A'></th></span></q></dt></tr></i><div id='sHI3A'><tfoot id='sHI3A'></tfoot><dl id='sHI3A'><fieldset id='sHI3A'></fieldset></dl></div>
          <tfoot id='sHI3A'></tfoot>

          <small id='sHI3A'></small><noframes id='sHI3A'>

            • <bdo id='sHI3A'></bdo><ul id='sHI3A'></ul>

                <tbody id='sHI3A'></tbody>
                  本文介绍了django - 使用 get_or_create 自动创建用户时设置用户权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  Django 1.5,python 2.6

                  Django 1.5, python 2.6

                  模型在特定条件下自动创建用户:

                  The model automatically creates a user under certain conditions:

                  User.objects.get_or_create(username=new_user_name, is_staff=True) 
                  u = User.objects.get(username=new_user_name)
                  u.set_password('temporary')
                  

                  除了设置用户名、密码和 is_staff 状态之外,我还想设置用户的权限 - 类似:

                  In addition to setting the username, password, and is_staff status, I would like to set the user's permissions - something like:

                  u.user_permissions('Can view poll')
                  

                  u.set_permissions('Can change poll')
                  

                  这可能吗?谢谢!

                  推荐答案

                  使用 addremove 方法:

                  Use add and remove methods:

                   from django.contrib.auth.models import Permission
                   permission = Permission.objects.get(name='Can view poll')
                   u.user_permissions.add(permission)
                  

                  这篇关于django - 使用 get_or_create 自动创建用户时设置用户权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  What happens when you compare 2 pandas Series(当你比较 2 个 pandas 系列时会发生什么)
                  Quickly find differences between two large text files(快速查找两个大文本文件之间的差异)
                  Python - Compare 2 files and output differences(Python - 比较 2 个文件和输出差异)
                  Why do comparisions between very large float values fail in python?(为什么在 python 中非常大的浮点值之间的比较会失败?)
                  Dictionary merge by updating but not overwriting if value exists(字典通过更新合并,但如果值存在则不覆盖)
                  Find entries of one text file in another file in python(在python中的另一个文件中查找一个文本文件的条目)
                      <bdo id='VVNFE'></bdo><ul id='VVNFE'></ul>

                        <tbody id='VVNFE'></tbody>
                      <legend id='VVNFE'><style id='VVNFE'><dir id='VVNFE'><q id='VVNFE'></q></dir></style></legend>
                        <tfoot id='VVNFE'></tfoot>

                            <i id='VVNFE'><tr id='VVNFE'><dt id='VVNFE'><q id='VVNFE'><span id='VVNFE'><b id='VVNFE'><form id='VVNFE'><ins id='VVNFE'></ins><ul id='VVNFE'></ul><sub id='VVNFE'></sub></form><legend id='VVNFE'></legend><bdo id='VVNFE'><pre id='VVNFE'><center id='VVNFE'></center></pre></bdo></b><th id='VVNFE'></th></span></q></dt></tr></i><div id='VVNFE'><tfoot id='VVNFE'></tfoot><dl id='VVNFE'><fieldset id='VVNFE'></fieldset></dl></div>

                            <small id='VVNFE'></small><noframes id='VVNFE'>