applegrew/django-select2 — pull request #129 by shchemelevev (2014-10-07 12:09:05+00:00)
Title: removed unnecessary db request

We have no db server on the build server.
When I had tryed to collect static i saw this error:
Traceback (most recent call last):
File "./manage.py", line 14, in
execute_from_command_line(sys.argv)
File "/home/noname/.virtualenvs/master/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/home/noname/.virtualenvs/master/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute
django.setup()
File "/home/noname/.virtualenvs/master/local/lib/python2.7/site-packages/django/__init__.py", line 21, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/noname/.virtualenvs/master/local/lib/python2.7/site-packages/django/apps/registry.py", line 115, in populate
app_config.ready()
File "/home/noname/.virtualenvs/master/local/lib/python2.7/site-packages/django/contrib/admin/apps.py", line 22, in ready
self.module.autodiscover()
File "/home/noname/.virtualenvs/master/local/lib/python2.7/site-packages/django/contrib/admin/__init__.py", line 23, in autodiscover
autodiscover_modules('admin', register_to=site)
File "/home/noname/.virtualenvs/master/local/lib/python2.7/site-packages/django/utils/module_loading.py", line 74, in autodiscover_modules
import_module('%s.%s' % (app_config.name, module_to_search))
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/home/noname/dev/site/unicom/payments/admin.py", line 9, in
from unicom.payments.forms import TariffPlanAdminForm
File "/home/noname/dev/site/unicom/payments/forms.py", line 39, in
class TariffPlanAdminForm(forms.ModelForm):
File "/home/noname/dev/site/unicom/payments/forms.py", line 45, in TariffPlanAdminForm
widget=django_select2.AutoHeavySelect2Widget
File "/home/noname/.virtualenvs/master/local/lib/python2.7/site-packages/django_select2/fields.py", line 305, in __call__
if not queryset and hasattr(cls, '_subclass_queryset'):
File "/home/noname/.virtualenvs/master/local/lib/python2.7/site-packages/django/db/models/query.py", line 145, in __nonzero__
self._fetch_all()
File "/home/noname/.virtualenvs/master/local/lib/python2.7/site-packages/django/db/models/query.py", line 966, in _fetch_all
self._result_cache = list(self.iterator())
File "/home/noname/.virtualenvs/master/local/lib/python2.7/site-packages/django/db/models/query.py", line 265, in iterator
for row in compiler.results_iter():
File "/home/noname/.virtualenvs/master/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 700, in results_iter
for rows in self.execute_sql(MULTI):
File "/home/noname/.virtualenvs/master/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 784, in execute_sql
cursor = self.connection.cursor()
File "/home/noname/.virtualenvs/master/local/lib/python2.7/site-packages/django/db/backends/__init__.py", line 165, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "/home/noname/.virtualenvs/master/local/lib/python2.7/site-packages/django/db/backends/__init__.py", line 138, in _cursor
self.ensure_connection()
File "/home/noname/.virtualenvs/master/local/lib/python2.7/site-packages/django/db/backends/__init__.py", line 133, in ensure_connection
self.connect()
File "/home/noname/.virtualenvs/master/local/lib/python2.7/site-packages/django/db/utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/home/noname/.virtualenvs/master/local/lib/python2.7/site-packages/django/db/backends/__init__.py", line 133, in ensure_connection
self.connect()
File "/home/noname/.virtualenvs/master/local/lib/python2.7/site-packages/django/db/backends/__init__.py", line 122, in connect
self.connection = self.get_new_connection(conn_params)
File "/home/noname/.virtualenvs/master/local/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 134, in get_new_connection
return Database.connect(**conn_params)
File "/home/noname/.virtualenvs/master/local/lib/python2.7/site-packages/psycopg2/__init__.py", line 164, in connect
conn = _connect(dsn, connection_factory=connection_factory, async=async)
django.db.utils.OperationalError: could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432?

This fix will remove useless query to database server.