Hi,
We are using Django for our ecommerce site.
I have some confusion on when the code gets executed in Django. I have a
django form with a choice field in module m1.py:
class SomeForm(forms.Form):
field = forms.ChoiceField(choices=get_choices())
def get_choices():
return some choices
In views.py, I have imported SomeForm:
from app.m1 import SomeForm
class SomeFormView(Formview):
form = SomeForm
...rest of the view code
When I run the django project using ./manage.py runserver, I am surprised
to see that get_choices gets executed. This is undesirable as I can have a
Django queryset in get_choices and I do not want unnecessary DB access.
It would be really helpful if someone can shed some light on the above and
tell me what exactly is happening. How can I avoid get_choices getting
executed during django start or running? get_choices should only get
executed when SomeFormView is accessed.
Thanks.
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/419b19a4-6ba1-4a27-8c27-f0d65b34a8bb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.