Opened 18 years ago

Closed 17 years ago

#3756 closed (duplicate)

ordering with two levels of ForeignKey in the admin interface

Reported by: mssnlayam@… Owned by: nobody
Component: contrib.admin Version: dev
Severity: Keywords:
Cc: mssnlayam@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I don't know if this bug is the same as #3002, #2076. I am reporting this nevertheless.

The Django admin throws an exception with the following code when viewing the Paragraph table.

class Reporter(models.Model):
    name = models.CharField(maxlength=30)

class Article(models.Model):
    name = models.CharField(maxlength=30)
    reporter = models.ForeignKey(Reporter)

    class Meta:
        ordering = ('reporter',)

class Paragraph(models.Model):
    name = models.CharField(maxlength=30)
    article = models.ForeignKey(Article)

    class Admin:
        list_display = ('name', 'article')

    class Meta:
        ordering = ('article',)

Here is the traceback

Traceback (most recent call last):
File "/tmp/foo/django/django-src/django/core/handlers/base.py" in get_response
  77. response = callback(request, *callback_args, **callback_kwargs)
File "/tmp/foo/django/django-src/django/contrib/admin/views/decorators.py" in _checklogin
  55. return view_func(request, *args, **kwargs)
File "/tmp/foo/django/django-src/django/views/decorators/cache.py" in _wrapped_view_func
  39. response = view_func(request, *args, **kwargs)
File "/tmp/foo/django/django-src/django/contrib/admin/views/main.py" in change_list
  760. cl = ChangeList(request, model)
File "/tmp/foo/django/django-src/django/contrib/admin/views/main.py" in __init__
  572. self.get_results(request)
File "/tmp/foo/django/django-src/django/contrib/admin/views/main.py" in get_results
  630. result_list = list(self.query_set)
File "/tmp/foo/django/django-src/django/db/models/query.py" in __iter__
  108. return iter(self._get_data())
File "/tmp/foo/django/django-src/django/db/models/query.py" in _get_data
  468. self._result_cache = list(self.iterator())
File "/tmp/foo/django/django-src/django/db/models/query.py" in iterator
  181. cursor.execute("SELECT " + (self._distinct and "DISTINCT " or "") + ",".join(select) + sql, params)
File "/tmp/foo/django/django-src/django/db/backends/util.py" in execute
  12. return self.cursor.execute(sql, params)
File "/tmp/foo/django/django-src/django/db/backends/sqlite3/base.py" in execute
  93. return Database.Cursor.execute(self, query, params)

  OperationalError at /admin/foo/paragraph/
  no such column: foo_article.reporter

The offending query is

SELECT
    "foo_paragraph"."id",
    "foo_paragraph"."name",
    "foo_paragraph"."article_id",
    "foo_article"."id",
    "foo_article"."name",
    "foo_article"."reporter_id",
    "foo_reporter"."id",
    "foo_reporter"."name"
FROM
    "foo_paragraph" , "foo_article", "foo_reporter"
WHERE
    "foo_paragraph"."article_id" = "foo_article"."id" AND
    "foo_article"."reporter_id" = "foo_reporter"."id"
ORDER BY
    "foo_article"."reporter" ASC

There is no column foo_article.reporter. The column name is foo_article.reporter_id.

Change History (2)

comment:1 by anonymous, 18 years ago

Summary: order_by with two levels of ForeignKey in the admin interfaceordering with two levels of ForeignKey in the admin interface

comment:2 by Jacob, 17 years ago

Resolution: duplicate
Status: newclosed

This is a duplicate of either #3002 or #2076 (I'm not sure which, and those two might be dups as well).

Note: See TracTickets for help on using tickets.
Back to Top