On Thursday, 12 April 2012 13:09:54 UTC+1, guettli wrote: > > Hi, > > sometimes it happens, that db queries get executed at import time (during > importing the file by the interpreter). > That's waste of time a resources. > Why? Imports only happen the first time a process accesses a module. A process lasts for many requests.
> Is there a way to test how many queries get executing during import? I > want some automated way to detect these db queries. > > Example: > > def mychoices(): > for obj in MyModel.objects.all(): # this hits the db during import. > That's not good. > .... > > class MyForm(forms.Form): > foo=forms.ChoiceField(choices=mychoices()) > The problem caused by this being executed at import time is not a "waste of time and resources", but the fact that if you add objects to MyModel, they won't appear in the MyForm.foo choices, until the process is restarted - which could be several days. -- DR. -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/XwdAWoqNwv8J. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.