当尝试在 Django 管理中导航到“添加演示文稿”时,我必须等待大约 1 分钟才能呈现响应。问题是我在数据库中有大约 500 张幻灯片,管理员正在选择所有幻灯片三个不同的时间来填写菜单。我的模型定义显然做错了,因为我不希望这么多的数据使我的服务器瘫痪。任何关于为什么我在定义关系或使用 django 管理员的方式中遇到此问题的可见性?
class PresentationTitle(models.Model):
title = models.CharField(max_length=255)
order_number = models.IntegerField(default=0)
def __unicode__(self):
return self.title
class PresentationUser(models.Model):
user = models.OneToOneField(User)
authorized_modules = models.ManyToManyField(PresentationTitle)
class Presentation(models.Model):
title = models.ForeignKey(PresentationTitle)
user = models.ForeignKey(PresentationUser)
presentation_date = models.DateTimeField()
def __unicode__(self):
return self.title.title
class Slide(models.Model):
....
submodule = models.ForeignKey(Submodule)
presentation = models.ManyToManyField(Presentation, through='PresentationSlide')
...
class Meta:
order_with_respect_to = 'submodule'
ordering = ['order']
class PresentationSlide(models.Model):
presentation = models.ForeignKey(Presentation)
slide = models.ForeignKey(Slide)
slide_order = models.IntegerField()
此外,我的管理员包含:
class PresentationSlideInline(admin.StackedInline):
model = PresentationSlide
class PresentationAdmin(admin.ModelAdmin):
inlines = [PresentationSlideInline]
admin.site.register(Presentation, PresentationAdmin)
可以理解的是,从 中删除仅具有 PresentationAdminadmin.site.register
会使其加载响应非常快。