Opened 12 years ago

Closed 11 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: master
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


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/" in get_response
  77. response = callback(request, *callback_args, **callback_kwargs)
File "/tmp/foo/django/django-src/django/contrib/admin/views/" in _checklogin
  55. return view_func(request, *args, **kwargs)
File "/tmp/foo/django/django-src/django/views/decorators/" in _wrapped_view_func
  39. response = view_func(request, *args, **kwargs)
File "/tmp/foo/django/django-src/django/contrib/admin/views/" in change_list
  760. cl = ChangeList(request, model)
File "/tmp/foo/django/django-src/django/contrib/admin/views/" in __init__
  572. self.get_results(request)
File "/tmp/foo/django/django-src/django/contrib/admin/views/" in get_results
  630. result_list = list(self.query_set)
File "/tmp/foo/django/django-src/django/db/models/" in __iter__
  108. return iter(self._get_data())
File "/tmp/foo/django/django-src/django/db/models/" in _get_data
  468. self._result_cache = list(self.iterator())
File "/tmp/foo/django/django-src/django/db/models/" in iterator
  181. cursor.execute("SELECT " + (self._distinct and "DISTINCT " or "") + ",".join(select) + sql, params)
File "/tmp/foo/django/django-src/django/db/backends/" in execute
  12. return self.cursor.execute(sql, params)
File "/tmp/foo/django/django-src/django/db/backends/sqlite3/" 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

    "foo_paragraph" , "foo_article", "foo_reporter"
    "foo_paragraph"."article_id" = "foo_article"."id" AND
    "foo_article"."reporter_id" = "foo_reporter"."id"
    "foo_article"."reporter" ASC

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

Change History (2)

comment:1 Changed 12 years ago by anonymous

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

comment:2 Changed 11 years ago by Jacob

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