#6649: Can't order by a ForeignKey relation
-----------------------+----------------------------------------------------
Reporter: toomim | Owner: nobody
Status: new | Component: Core framework
Version: SVN | Keywords:
Stage: Unreviewed | Has_patch: 0
-----------------------+----------------------------------------------------
I have a model Venue that is sorted by "-pub_date":
{{{
class Venue(models.Model):
....
pub_date = models.DateField('Published date', help_text="Only the year
and month will be used")
class Admin: pass
class Meta:
ordering = ("-pub_date",)
}}}
And a model PubAward that foreignkeys Venue, and sorts by Venue:
{{{
class PubAward(models.Model):
...
venue = models.ForeignKey(Venue, blank=True)
class Admin: pass
class Meta:
ordering = ("venue",)
}}}
But when I open an admin page on PubAward, it tries to list all PubAwards
and gives me the following error:
{{{
no such column: main_venue.-pub_date
}}}
Here's the full stack trace:
{{{
Environment:
Request Method: GET
Request URL: http://together.cs.washington.edu:8082/admin/main/pubaward/
Django Version: 0.97-pre-SVN-7149
Python Version: 2.4.4
Installed Applications:
['django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'dubweb.main',
'django.contrib.admin']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.middleware.doc.XViewMiddleware')
Traceback:
File "/usr/lib/python2.4/site-packages/django/core/handlers/base.py" in
get_response
82. response = callback(request, *callback_args,
**callback_kwargs)
File "/usr/lib/python2.4/site-
packages/django/contrib/admin/views/decorators.py" in _checklogin
56. return view_func(request, *args, **kwargs)
File "/usr/lib/python2.4/site-packages/django/views/decorators/cache.py"
in _wrapped_view_func
39. response = view_func(request, *args, **kwargs)
File "/usr/lib/python2.4/site-packages/django/contrib/admin/views/main.py"
in change_list
776. cl = ChangeList(request, model)
File "/usr/lib/python2.4/site-packages/django/contrib/admin/views/main.py"
in __init__
582. self.get_results(request)
File "/usr/lib/python2.4/site-packages/django/contrib/admin/views/main.py"
in get_results
640. result_list = list(self.query_set)
File "/usr/lib/python2.4/site-packages/django/db/models/query.py" in
__iter__
114. return iter(self._get_data())
File "/usr/lib/python2.4/site-packages/django/db/models/query.py" in
_get_data
483. self._result_cache = list(self.iterator())
File "/usr/lib/python2.4/site-packages/django/db/models/query.py" in
iterator
189. cursor.execute("SELECT " + (self._distinct and "DISTINCT "
or "") + ",".join(select) + sql, params)
File "/usr/lib/python2.4/site-packages/django/db/backends/util.py" in
execute
18. return self.cursor.execute(sql, params)
File "/usr/lib/python2.4/site-packages/django/db/backends/sqlite3/base.py"
in execute
133. return Database.Cursor.execute(self, query, params)
Exception Type: OperationalError at /admin/main/pubaward/
Exception Value: no such column: main_venue.-pub_date
}}}
This also occurs without the hyphen in "-pub_date".
--
Ticket URL: <http://code.djangoproject.com/ticket/6649>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" 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-updates?hl=en
-~----------~----~----~----~------~----~------~--~---