[英]Django - model page taking long to load when adding new data
I have a fairly simple model with a many to many relationship to another model. 我有一个相当简单的模型,该模型与另一个模型有很多关系。 rom django.db import models
rom django.db导入模型
class MechanismReference(models.Model):
reference = models.TextField(help_text=u'References to support the target information like PMID, KEGGID,etc.')
reference_type = models.CharField(max_length=10, blank=True,
help_text='Type of reference, the reference from KEGG, PIMD, PMC or other')
mech_reference = models.ManyToManyField('Mechanism', blank=True, null=True, max_length=150)
def sort_data(self):
return self.mech_reference.order_by('pk')
def __unicode__(self):
return u'%s %s (%s)' % (
self.reference_type, self.reference, ",".join(mechanism.molecule for mechanism in self.mech_reference.all()))
The Mechanism models is like this: 机制模型如下:
class Mechanism(models.Model):
target = models.ForeignKey('TargetDictionary', blank=True, null=True,
help_text=u'Target associated with this mechanism of action (foreign key to target_dictionary table')
molecule = models.ForeignKey('MoleculeDictionary', blank=False, null=False,
help_text=u'Molregno for the drug (foreign key to molecule_dictionary table)')
mechanism_type = models.ForeignKey('MechanismType', blank=True, null=True,
help_text=u'Type of action of the drug on the target e.g., agonist/antagonist etc (foreign key to action_type table)')
class Meta:
ordering = ['molecule', ]
def __unicode__(self):
#
if self.mechanism_type:
return u'%s %s %s' % (self.molecule.molecule, self.target.name, self.mechanism_type.description)
elif self.mechanism_type is None:
return u'%s %s %s' % (self.molecule.molecule, self.target.name, self.mechanism_type.moa_qualifier)
else:
return u'%s %s %s' % (self.molecule.molecule, self.target.name, str(self.pk))
The mechanism model has got 2041 records. 机理模型有2041条记录。 The reference page loads Okie when it executes select * from mechanism_reference.
该参考页在执行Okie时会从选择机制*中加载Okie。 But whenever I add a new mechanism reference it takes so long sometime I get a server error(500).
但是,每当我添加一个新的机制引用时,它花费的时间太长了,我会收到服务器错误(500)。 Obviously, the page would have all the records form Mechanism table pre-populated to enable adding a many to many relationship for a given reference.
显然,该页面将预先填充了机制表中的所有记录,以便为给定的引用添加多对多关系。 Can anyone point me why is it slow and is there a way to reduce the loading up time?
谁能指出我为什么这么慢,有没有办法减少加载时间?
Again this is much slower in development or production server than my localserver. 同样,这在开发或生产服务器中比本地服务器要慢得多。
I use xadmin and individual models doesn't have designated view. 我使用xadmin,各个模型没有指定的视图。 I have added my view and base_site.html.
我已经添加了我的视图和base_site.html。
View: 视图:
from django.shortcuts import render
from django.http import HttpResponse
from django.template import RequestContext, loader
def index(request):
template = loader.get_template('idg/index.html')
context = RequestContext(request, {})
return HttpResponse(template.render(context))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.