2011-04-17 49 views
0

試圖request.POST數據綁定到窗體時,我得到的約20 -30秒無法解釋延遲:延遲綁定request.POST數據時,形成在Django

CompanyFormset = modelformset_factory(Company, form=EditCompanyForm, extra=0) 

    if request.method == 'POST': 
     formset = CompanyFormset(request.POST) 
     if formset.is_valid(): 
      formset.save() 

它只是發生在一個服務器,無論我使用的是開發服務器還是mod_wsgi。當在我的開發計算機上嘗試時,一切工作都很快。如果我嘗試通過手動賦值來保存模型,它應該是很快的。

延遲只發生在這條線:

formset = CompanyFormset(request.POST) 

..和我沒有更多的想法是什麼導致它或在何處尋找問題的原因。

有什麼建議該怎麼辦?

這裏是模型過於:

class Company(models.Model): 
name = models.CharField(_('name'),blank=True, max_length=200) 
type_of_corporation = models.CharField(_('type of organization'),blank=True, max_length=100) 
tax_number = models.CharField(_('tax number'),blank=True, max_length=100) 
created_at = models.DateTimeField(auto_now_add = True) 
updated_at = models.DateTimeField(auto_now = True) 
logo = models.FileField(_('logo'),upload_to='bex/logos', blank=True, null=True) 
description = models.TextField(_('description'),blank=True) 
street = models.CharField(_('street'),blank=True, max_length=100) 
city = models.CharField(_('city'),blank=True, max_length=100) 
zip = models.CharField(_('zip'),blank=True, max_length=50) 
region = models.CharField(_('region'),blank=True, max_length=100) 
COUNTRIES = (
    ('Croatia', 'Croatia'), 
    ('Slovenia', 'Slovenia'), 
) 
country = models.CharField(_('country'),max_length=20, choices=COUNTRIES) 
telephone = models.CharField(_('telephone'),blank=True, max_length=20) 
fax = models.CharField(_('fax'),blank=True, max_length=20) 
email = models.EmailField(_('email'),blank=True) 
website = models.URLField(_('website'),null=True, blank=True, verify_exists=False) 
representing_person = models.CharField(_('representing person'), blank=True, max_length=100) 
owner = models.ForeignKey(User, blank=True, null=True, verbose_name=_('owner'), related_name='company_owner') 
owner_approved = models.BooleanField(blank=True) 
company_approved = models.BooleanField(default=True) 
business_category = models.ForeignKey(BusinessCategory, blank=True, null=True, verbose_name=_('business category')) 
subscription_date = models.DateTimeField(_('subscription date'),blank=True, null=True) 
score = models.IntegerField(null=True, blank=True) 
votes = models.IntegerField(null=True, blank=True) 

""" company data needs to have ratings, comments, category and business tags """ 

class Admin: 
    list_display = ('',) 
    search_fields = ('',) 
    save_as = True 

class Meta: 
    verbose_name = _('Company') 
    verbose_name_plural = _('Companies') 


def rating_allowed(self): 

    if not self.subscription_date: 
     try: 
      user = User.objects.get(id=self.owner.id) 
      if (datetime.today() - user.date_joined).days < 30: 
       rating_allowed = True 
     except: 
      rating_allowed = False 
    else: 
     if (datetime.today() - self.subscription_date).days < 365: 
      rating_allowed = True 
     else: 
      rating_allowed = False 
    self.rating_allowed = rating_allowed 
    return self.rating_allowed 

def get_absolute_url(self): 
    return "/companies/%i/" % self.id 

def __unicode__(self): 
    return self.name 
+0

發佈公司模型也請 – 2011-04-17 10:16:56

+0

在這裏,添加到上面的帖子。 – tmilovan 2011-04-17 11:23:45

回答

1

一切看起來都還好模型。您可以嘗試優秀的django debug toolbar報告時間,並可能幫助您確定需要這麼長時間。

+0

嘗試過它,並嘗試與pdb。查詢在我的開發筆記本電腦和服務器上花費相同的時間。當與pdb一步一步地在我上面提到的線路上停頓時,所有東西都會凍結20到30秒,然後繼續。如果我手動將值通過pdb,然後驗證並保存模型,它可以快速保存。也許問題的原因是django之外,但我無法想象它會是什麼。 – tmilovan 2011-04-17 15:43:30