Django管理员在尝试编辑/创建时挂起(直到超时错误)为特定模型 [英] Django admin hangs (until timeout error) for a specific model when trying to edit/create

查看:176
本文介绍了Django管理员在尝试编辑/创建时挂起(直到超时错误)为特定模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个人现在正在驾驶我的坚果。以前没有发生过(甚至有客户需要的用户手册的屏幕截图)。



我首先在生产服务器上注意到,然后我检查并发生在Django附带的dev服务器中。该模型出现在django管理员的主页上,我可以点击它,它将显示销售点列表。只要我想编辑一个现有的实例或者创建一个新的实例,问题就会出现。



我只需点击链接(或放在吧台上),它就挂起

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

这是模型的注册。所有型号都注册在管理应用程序中,用户测试这是一个超级用户。模型是:

  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)

加上一些不应该真正重要的方法。此外,在此之前的最后一次,我测试了管理员是在创建所有这些方法后,所以这不应该是这样的。



管理员很少有访问此页面。通常它只是列出了PoS,但仍然困扰着我。任何想法为什么可能挂?所有其他型号都正常工作。



这是在Django 1.2.5和1.3上发生的。



编辑:



我修改了超时限制。它工作,但不知何故,它需要几分钟的时间才能实际发生。所以,在后台有一些事情要花时间。我不明白它是如何发生在这个模型,它发生在不同的环境(和小数据集)








问题是邮政编码清单很大(几十万),外键字段作为html选择加载标签,这意味着它加载每个单个条目。这是一个问题,有多少数据是简单的。



现在我不知道如何控制外键在管理中显示的方式。任何人都可以帮助吗?

解决方案

在您的admin.py文件中,在适当的管理类下,设置

  raw_id_fields =('zipcode',)

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



是否有一个原因,您正在设置zipcode作为自己的模型,而不是使用CharField或实际的邮政编码 modelfield


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).

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.

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.

This is happening on both Django 1.2.5 and 1.3

EDIT:

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.

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?

解决方案

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

raw_id_fields = ('zipcode',)

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

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管理员在尝试编辑/创建时挂起(直到超时错误)为特定模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆