Opened 7 years ago

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

Description

This is the newforms-admin equivalent of #3002. See http://code.djangoproject.com/ticket/3002#comment:3

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

This bug can be reproduced by this minimal app:

# models.py

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',)


admin.site.register(Poll, PollAdmin)
admin.site.register(Choice, ChoiceAdmin)
# admin.py

from django.contrib import admin

class PollAdmin(admin.ModelAdmin):
    pass

class ChoiceAdmin(admin.ModelAdmin):
    pass

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

Environment:

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:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'nfa_test.issues']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.middleware.doc.XViewMiddleware')


Traceback:
File "/mnt/disk2/ramiro/hg-repos/django/t3002-nf-a/django/core/handlers/base.py" in get_response
  82.                 response = callback(request, *callback_args, **callback_kwargs)
File "/mnt/disk2/ramiro/hg-repos/django/t3002-nf-a/django/contrib/admin/sites.py" in root
  137.                 return self.model_page(request, *url.split('/', 2))
File "/mnt/disk2/ramiro/hg-repos/django/t3002-nf-a/django/contrib/admin/sites.py" in model_page
  154.         return admin_obj(request, rest_of_url)
File "/mnt/disk2/ramiro/hg-repos/django/t3002-nf-a/django/contrib/admin/options.py" in __call__
  242.             return self.changelist_view(request)
File "/mnt/disk2/ramiro/hg-repos/django/t3002-nf-a/django/contrib/admin/options.py" 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/main.py" in __init__
  148.         self.query_set = self.get_query_set()
File "/mnt/disk2/ramiro/hg-repos/django/t3002-nf-a/django/contrib/admin/views/main.py" 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/query.py" in order_by
  427.         obj.query.add_ordering(*field_names)
File "/mnt/disk2/ramiro/hg-repos/django/t3002-nf-a/django/db/models/sql/query.py" 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: ['issues_poll.id']

Attachments (1)

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

Download all attachments as: .zip

Change History (4)

Changed 7 years ago by ramiro

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

comment:1 Changed 7 years ago by ramiro

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

comment:2 Changed 7 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 7 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