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

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

  1. <tfoot id='HcH3t'></tfoot>
      • <bdo id='HcH3t'></bdo><ul id='HcH3t'></ul>

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

    1. Django 管理员注册内联用户配置文件管理员的问题

      Issue with Django admin registering an inline user profile admin(Django 管理员注册内联用户配置文件管理员的问题)

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

                <small id='0tY4s'></small><noframes id='0tY4s'>

                本文介绍了Django 管理员注册内联用户配置文件管理员的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我目前正在开发一个 django 项目.我正在尝试将 UserProfile 模型内联添加到我的 User 模型中.在我的 models.py 中,我有:

                I'm currently working on a django project. I'm attempting to add a UserProfile model inline to my User model. In my models.py I have:

                class UserProfile(models.Model):
                    '''
                    Extension to the User model in django admin.
                    '''
                    user = models.ForeignKey(User)
                    site_role = models.CharField(max_length=128, choices=SITE_ROLE)
                    signature = models.CharField(max_length=128)
                    position_title = models.CharField(max_length=128)
                    on_duty = models.BooleanField(default=False)
                    on_duty_order = models.IntegerField()
                

                在我的 admin.py 中有:

                In my admin.py I have:

                class UserProfileInline(admin.StackedInline):
                    model = UserProfile
                
                class UserAdmin(admin.ModelAdmin):
                    inlines = [UserProfileInline]
                
                
                admin.site.unregister(User)
                admin.site.register(User, UserAdmin)
                

                当我运行开发服务器时(是的,我已经重新启动它)我得到以下异常:

                When I run the development server (yes, I have restarted it) I get the following exception:

                NotRegistered at /admin
                The model User is not registered
                

                此异常来自 admin.site.unregister(User) 行.

                但是,当我注释掉该行时,我得到以下异常:

                However, when I comment out that line, I get the following exception:

                AlreadyRegistered at /admin
                The model User is already registered
                

                我的 django 设置似乎有点两极.我花了一个小时左右的时间研究这个问题,我的代码似乎对其他人来说很好用.有没有人知道为什么会发生这种情况?

                Something about my django setup seems to be a little bi-polar. I've spent an hour or so researching this problem and the code I have seems to work great for others. Does anyone have any insight into why this might be happening?

                谢谢,特拉维斯

                推荐答案

                我的猜测是你要么正在做一些疯狂的模块导入......或者......你的 settings.INSTALLED_APPS列表.确保 'django.contrib.auth' 出现在列表中,位于替换默认管理员的应用之前.该列表应如下所示:

                my guess is that you either are doing some crazy module importing... or... you have an ordering problem in your settings.INSTALLED_APPS list. Make sure that 'django.contrib.auth' appears on your list before your app that is replacing the default admin. The list should look something like this:

                INSTALLED_APPS = (
                    # django apps first
                    'django.contrib.auth',
                    'django.contrib.contenttypes',
                    'django.contrib.sessions',
                    'django.contrib.sites',
                    'django.contrib.messages',
                    'django.contrib.admin',
                
                    # your stuff from here on
                    'yourproject.userstuff',
                )
                

                这样 django 的应用程序会注册 User 模型,然后您使用自己的 ModelAdmin 注销并重新注册它.

                That way django's app registers the User model, and then you unregister and re-register it with your own ModelAdmin.

                这篇关于Django 管理员注册内联用户配置文件管理员的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)
                Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)
                Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)
                Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)
                Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)
                Grouping pandas DataFrame by 10 minute intervals(按10分钟间隔对 pandas 数据帧进行分组)
                • <bdo id='m0BEd'></bdo><ul id='m0BEd'></ul>
                  <legend id='m0BEd'><style id='m0BEd'><dir id='m0BEd'><q id='m0BEd'></q></dir></style></legend>

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

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

                    <tfoot id='m0BEd'></tfoot>

                            <tbody id='m0BEd'></tbody>