I have this code in a view:
x = [(chld.id,
chld.name) for chld in City.objects.all()]
print x
it works perfectly in the view and in the shell also
But when I put it under __init__ in a form I get a programming error.
The code is here:
class Edituserform(forms.Form):
"""
Form to edit the user credentials.
"""
def __init__(self, *args, **kwargs):
super(Edituserform, self).__init__(*args, **kwargs)
# Generate choices
self.fields['city'].choices = [(chld.id,
chld.name) for chld in City.objects.all()]
and the error is here:
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8888/edituser/
Django Version: 1.3 pre-alpha SVN-13494
Python Version: 2.6.2
Installed Applications:
['django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.admin',
'ipss.web']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware')
Traceback:
File "/usr/lib/python2.6/site-packages/django/core/handlers/base.py" in
get_response
100. response = callback(request, *callback_args,
**callback_kwargs)
File
"/usr/lib/python2.6/site-packages/django/contrib/auth/decorators.py" in
_wrapped_view
25. return view_func(request, *args, **kwargs)
File "/usr/lib/python2.6/site-packages/django/db/transaction.py" in
_commit_on_success
299. res = func(*args, **kw)
File "/home/lawgon/ipss/../ipss/web/views.py" in edituser
283. form = Edituserform(data)
File "/home/lawgon/ipss/../ipss/web/views.py" in __init__
192. chld.name) for chld in City.objects.all()]
File "/usr/lib/python2.6/site-packages/django/db/models/query.py" in
_result_iter
106. self._fill_cache()
File "/usr/lib/python2.6/site-packages/django/db/models/query.py" in
_fill_cache
760. self._result_cache.append(self._iter.next())
File "/usr/lib/python2.6/site-packages/django/db/models/query.py" in
iterator
269. for row in compiler.results_iter():
File "/usr/lib/python2.6/site-packages/django/db/models/sql/compiler.py"
in results_iter
672. for rows in self.execute_sql(MULTI):
File "/usr/lib/python2.6/site-packages/django/db/models/sql/compiler.py"
in execute_sql
727. cursor.execute(sql, params)
File "/usr/lib/python2.6/site-packages/django/db/backends/util.py" in
execute
15. return self.cursor.execute(sql, params)
File
"/usr/lib/python2.6/site-packages/django/db/backends/postgresql/base.py"
in execute
57. return self.cursor.execute(smart_str(sql,
self.charset), self.format_params(params))
Exception Type: DatabaseError at /edituser/
Exception Value: ERROR: current transaction is aborted, commands
ignored until end of transaction block
SELECT "web_city"."id", "web_city"."name" FROM "web_city"
--
regards
Kenneth Gonsalves
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
No comments:
Post a Comment