Opened 8 years ago

Closed 8 years ago

#7099 closed (fixed)

FieldError in newforms admin when Meta.ordering contains a FK

Reported by: ramiro Owned by: nobody
Component: contrib.admin Version: newforms-admin
Severity: Keywords: changelist newforms-admin FieldEerror fk ordering
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


This is the newforms-admin equivalent of #3002. See

Find attached patch fixing this (identical modulo lines offsets to the one attached to #3002).

This bug can be reproduced by this minimal app:


import datetime

from django.db import models
from django.contrib import admin

from admin import PollAdmin, ChoiceAdmin

class Poll(models.Model):
    question = models.CharField(max_length=200)

    def __unicode__(self):
        return self.question

class Choice(models.Model):
    poll = models.ForeignKey(Poll, null=True)
    choice = models.CharField(max_length=200)

    def __unicode__(self):
        return self.choice

    class Meta:
        ordering = ('poll',), PollAdmin), ChoiceAdmin)

from django.contrib import admin

class PollAdmin(admin.ModelAdmin):

class ChoiceAdmin(admin.ModelAdmin):

Problem shows itself when the "Choices" link is clicked in the admin index page. This is the traceback generated:


Request Method: GET
Request URL: http://ikki:8000/admin/issues/choice/
Django Version: 0.97-newforms-admin-SVN-unknown
Python Version: 2.4.4
Installed Applications:
Installed Middleware:

File "/mnt/disk2/ramiro/hg-repos/django/t3002-nf-a/django/core/handlers/" in get_response
  82.                 response = callback(request, *callback_args, **callback_kwargs)
File "/mnt/disk2/ramiro/hg-repos/django/t3002-nf-a/django/contrib/admin/" in root
  137.                 return self.model_page(request, *url.split('/', 2))
File "/mnt/disk2/ramiro/hg-repos/django/t3002-nf-a/django/contrib/admin/" in model_page
  154.         return admin_obj(request, rest_of_url)
File "/mnt/disk2/ramiro/hg-repos/django/t3002-nf-a/django/contrib/admin/" in __call__
  242.             return self.changelist_view(request)
File "/mnt/disk2/ramiro/hg-repos/django/t3002-nf-a/django/contrib/admin/" in changelist_view
  586.                 self.date_hierarchy, self.search_fields, self.list_select_related, self.list_per_page, self)
File "/mnt/disk2/ramiro/hg-repos/django/t3002-nf-a/django/contrib/admin/views/" in __init__
  148.         self.query_set = self.get_query_set()
File "/mnt/disk2/ramiro/hg-repos/django/t3002-nf-a/django/contrib/admin/views/" in get_query_set
  309.         qs = qs.order_by(order_type + lookup_order_field)
File "/mnt/disk2/ramiro/hg-repos/django/t3002-nf-a/django/db/models/" in order_by
  427.         obj.query.add_ordering(*field_names)
File "/mnt/disk2/ramiro/hg-repos/django/t3002-nf-a/django/db/models/sql/" in add_ordering
  1293.             raise FieldError('Invalid order_by arguments: %s' % errors)

Exception Type: FieldError at /admin/issues/choice/
Exception Value: Invalid order_by arguments: ['']

Attachments (1)

t7099-nf-a-r7484.diff (1.8 KB) - added by ramiro 8 years ago.
Patch fixing the bug, for nf-a as of r7484

Download all attachments as: .zip

Change History (4)

Changed 8 years ago by ramiro

Patch fixing the bug, for nf-a as of r7484

comment:1 Changed 8 years ago by ramiro

  • Has patch set
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 8 years ago by ramiro

  • Summary changed from FieldError in newforms admin when Meta.ordering contains by a FK to FieldError in newforms admin when Meta.ordering contains a FK

comment:3 Changed 8 years ago by ramiro

  • Resolution set to fixed
  • Status changed from new to closed

This was fixed in newforms-admin by the merge from trunk of [7492].

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