• <small id='Ag3GQ'></small><noframes id='Ag3GQ'>

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

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

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

        尝试编辑/创建时,特定模型的 Django 管理员挂起(直到超时错误)

        时间:2023-11-07

      2. <tfoot id='DpufT'></tfoot>

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

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

                <bdo id='DpufT'></bdo><ul id='DpufT'></ul>
              • <legend id='DpufT'><style id='DpufT'><dir id='DpufT'><q id='DpufT'></q></dir></style></legend>
                  本文介绍了尝试编辑/创建时,特定模型的 Django 管理员挂起(直到超时错误)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  这个现在让我发疯了.以前没有发生过(因为客户需要,我什至得到了用户手册的屏幕截图).

                  This one is driving me nuts right now. It was not happening before (even got screenshots I had to do for the user-manual since the customer required it).

                  我首先在生产服务器上注意到它,然后我检查并在 Django 附带的开发服务器中也发生了.该模型出现在 django admin 的主页上,我可以单击它,它将显示销售点列表.每当我想编辑现有实例或创建新实例时,就会出现问题.

                  I first noticed it on production server and then I checked and also happens in the dev server that comes with Django. The model appears on the main-page of the django admin, I can click it and it will display the list of point of sales. The problem comes whenever I want to edit an existing instance or create a new one.

                  我只需单击链接(或将其放在栏上),它就会挂起.

                  I just click on the link (or put it on the bar) and it just hangs.

                  class PointOfSaleAdmin(admin.ModelAdmin):
                      list_display = ('id','business', 'user', 'zipcode', 'address','date_registered')
                      list_filter = ('business',)
                      filter_horizontal = ('services',)
                  admin.site.register(models.PointOfSale, PointOfSaleAdmin)
                  

                  这就是模型的注册.所有模型都在管理应用程序中注册,并且要测试的用户是超级用户.型号为:

                  That's the registration of the model. All models are registered in the admin application and the user to test this is a super user. The model is:

                  class PointOfSale(models.Model):
                      user = models.ForeignKey(User)
                      zipcode = models.ForeignKey(Zipcode)
                      business = models.ForeignKey(Business)
                      services = models.ManyToManyField(Service, 
                          verbose_name='available services')
                      date_registered = models.DateField(auto_now_add=True)
                      address = models.CharField(max_length=300)
                  

                  加上一些不应该很重要的方法.另外,在此之前我上次测试管理员是在我创建所有这些方法之后,所以这不重要.

                  Plus a few methods that shouldn't really matter much. Plus, last time before this that I tested the admin was right after I created all those methods, so it shouldn't matter on this.

                  管理员很少需要访问此页面.通常它只是列出 PoS,但它仍然困扰着我.知道为什么它会被挂起吗?所有其他模型都运行良好.

                  The administrator very very rarely has to access this page. Usually it's just listing the PoS, but it still bothers me. Any idea of why it could be hanging? All other models are working just fine.

                  这发生在 Django 1.2.5 和 1.3 上

                  This is happening on both Django 1.2.5 and 1.3

                  我修改了超时限制.它正在工作,但不知何故,它需要几分钟才能真正发生.所以,背景中有一些东西需要很长时间.我不明白为什么它只发生在这个模型上,而且它发生在不同的环境(和小数据集)

                  I modified the timeout limits. It IS working, but somehow it takes several minutes for it to actually happen. So, there is something in the background that is taking ages. I don't understand how come it happens only for this model and it happens in different environments (and with small datasets)

                  我几乎想扇自己耳光.这么久没睡是我的错.

                  I almost feel like slapping myself. My fault for not sleeping for so long.

                  问题是邮政编码列表非常大(成千上万),并且外键字段作为 html 选择标记加载,这意味着它会加载每个条目.只是有多少数据是个问题.

                  The problem is that the zipcode list is pretty big (dozens of thousands) and the foreign key field is loaded as an html select tag, which means it loads every single entry. It's an issue with how much data there is simply.

                  现在我想知道如何控制外键在管理员中的显示方式.有人可以帮忙吗?

                  Now I wonder how to control the way the foreign key is displayed in the admin. Anyone could help with that?

                  推荐答案

                  在你的 admin.py 文件中,在相应的 admin 类下,设置

                  In your admin.py file, under the appropriate admin class, set

                  raw_id_fields = ('zipcode',)
                  

                  这将显示邮政编码的 PK 而不是下拉列表.

                  This will display the zipcode's PK instead of a dropdown.

                  是否有理由将邮政编码设置为自己的模型,而不是使用 CharField 或实际邮政编码 模型字段?

                  Is there a reason that you are setting up zipcode as it's own model instead of using a CharField or an actual zipcode modelfield?

                  这篇关于尝试编辑/创建时,特定模型的 Django 管理员挂起(直到超时错误)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:您可以更改 Django Admin 应用程序中的字段标签吗? 下一篇:Django 唯一、空和空白 CharField 在管理页面上给出“已经存在"错误

                  相关文章

                    <bdo id='OGmhA'></bdo><ul id='OGmhA'></ul>
                  <legend id='OGmhA'><style id='OGmhA'><dir id='OGmhA'><q id='OGmhA'></q></dir></style></legend>
                1. <small id='OGmhA'></small><noframes id='OGmhA'>

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

                    2. <tfoot id='OGmhA'></tfoot>