please, I sent last days fighting with db and django.
My problem is: I have database 500 Mb big ... In db there are not any many_to_many, foreing etc. so tables are not independent one to another. In django I have created model by using inspectdb. My problem is that once I call runserver I have to wait about 5 minutes before server starts. I have tried debug by use python -vv manage.py runserver to seee where the server get stuck, and it's always when try connect to the database.
I have tried same db structure with MySQL, PostgreSQL, MSSQL but all databases behaves same. Also on different machines and different django versions.
Once I created db dump without datas, only db structure so size of db wat about 16Kb and than Django server starts fast(miliseconds).
I use django version 1.9.5 but have tried also 1.8
Please every tip will be appreciated, actually I am at the end of my ideas where to search for the problem.
Thanks
So, after few days debugging and asking on IRC, I have a reason why the runserver (and almost every manage.py command) takes that long time. Django seems does not check SQL queries in views.py where I have most of my SQL queries. But I have two easy queries in my forms.py, to fill dropdown in my form and that cause whole problem.
So now I know where problem is, but I am thinking how to resolve it. Thing is that I need data from my models in my form.
My form looks:
def get_vendor_set():
"""
Returns set of contributors to use as choices
"""
vendor_set = [
('Availability', 'Availability'),
('No Competitor', 'No Competitor'),
('Popularity', 'Popularity'),
]
contrib = CompetitorLastPrice.objects.order_by('vendor')
for con in contrib:
vendor_set.append((con.vendor,con.vendor))
return sorted(set(vendor_set))
def get_sorg_set():
"""
Return set of sorg to use as choices
"""
sorg_set = []
sorg_cursor = CltSorg.objects.all()
for sorg in sorg_cursor:
sorg_set.append((sorg.sorg, sorg.sorg +' - '+ sorg.sorg_description))
return sorg_set
class FamilyForm(forms.ModelForm):
class Meta:
model = Family
fields = ['name', 'family_number', 'price_list', 'sorg', 'filter', 'linearity']
widgets = {
'sorg': forms.Select(choices=get_sorg_set()),
}
class CustomInlineFormset(BaseInlineFormSet):
"""
Custom formset that support initial data
"""
...
...
ContribFormSet = inlineformset_factory(Family, Templates, formset=CustomInlineFormset,
fields='__all__', min_num=1, extra=0,
widgets={'contributor' : forms.Select(choices=get_vendor_set())}
)
The problems causes those widgets... Is there any other way how to get data to the initial form (to the choice list) somewhere out of the forms.py ...I am thinking to do it in views.py somehow.
Thanks for any answer.
V.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments