Hi all!
I'm working on an app which has two classes:
# This one records acedemic journal name and related infomation:
class Journals(models.Model):
Name = models.CharField(u'Journal', max_length=200, unique=True)
IsSelected = models.BooleanField(u'If it is a special journal',
default = False)
IsTopped = models.BooleanField(u'Should it be placed at the top of
the journal selection box?',
default = False)
class Meta:
ordering = ('-IsSelected', '-IsTopped', 'Name', )
def __unicode__(self):
return u"%s" % (self.Name)
# This one records paper infomation:
class Paper(models.Model):
# Many other fields are ommitted.
Journal = models.ForeignKey(Journals, verbose_name="Journal Name")
And in a view, I wrote a query:
paper_list =
Paper.objects.filter(Journal='Science').order_by("-PublishedDate")
However, this one failed, complaining some DataError, invalid interger
type input grammar.
From the debug infomation, I learnt that Django tried to do a sql query
like:
'SELECT COUNT(*) FROM "paper_paper" WHERE "paper_paper"."Journal_id" =
E\'Science\' '
which would certainly fail, since 'Science' is a string, and that
Journal_id(an automatically defined field by Django) is of type integer.
The problem is, why Django mis-translated that query? And how could I
fix this problem?
Many thanks!
Detailed Debug info:
Environment:
Request Method: GET
Request URL: http://cmr.nju.edu.cn/Paper/Science/
Django Version: 1.1 pre-alpha SVN-9665
Python Version: 2.4.3
Installed Applications:
['django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.comments',
'django.contrib.admin',
'django.contrib.tagging',
'pld.globaltags',
'pld.home',
'pld.Profile',
'pld.news',
'pld.paper']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware')
Traceback:
File "/usr/lib64/python2.4/site-packages/django/core/handlers/base.py"
in get_response
86. response = callback(request, *callback_args,
**callback_kwargs)
File "/www/pld/paper/views.py" in byJournal
50. paper_page = paginator.page(page)
File "/usr/lib64/python2.4/site-packages/django/core/paginator.py" in page
37. number = self.validate_number(number)
File "/usr/lib64/python2.4/site-packages/django/core/paginator.py" in
validate_number
28. if number > self.num_pages:
File "/usr/lib64/python2.4/site-packages/django/core/paginator.py" in
_get_num_pages
60. if self.count == 0 and not self.allow_empty_first_page:
File "/usr/lib64/python2.4/site-packages/django/core/paginator.py" in
_get_count
48. self._count = self.object_list.count()
File "/usr/lib64/python2.4/site-packages/django/db/models/query.py" in count
296. return self.query.get_count()
File "/usr/lib64/python2.4/site-packages/django/db/models/sql/query.py"
in get_count
234. data = obj.execute_sql(SINGLE)
File "/usr/lib64/python2.4/site-packages/django/db/models/sql/query.py"
in execute_sql
1756. cursor.execute(sql, params)
File "/usr/lib64/python2.4/site-packages/django/db/backends/util.py" in
execute
19. return self.cursor.execute(sql, params)
Exception Type: DataError at /Paper/Science/
Exception Value: Error: Invalid Input Syntax for Integer: "Science"
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---