#3002: admin getting confused by "order_by" statements.
----------------------------------+-----------------------------------------
Reporter: [EMAIL PROTECTED] | Owner: adrian
Status: closed | Component: Admin interface
Version: | Resolution: duplicate
Keywords: | Stage: Unreviewed
Has_patch: 0 | Needs_docs: 0
Needs_tests: 0 | Needs_better_patch: 0
----------------------------------+-----------------------------------------
Comment (by ramiro <rm0 _at_ gmx.net>):
It seems to me this ticket is about a different issue that the one
described in #2076, that tickets is about a bug in the Django ORM and this
one is related to a bug of the Admin contrib app.
Even when a fix for #2076 is applied (by using the patch attached to that
ticket), the Admin app keeps generating the bug described here. So I would
suggest to reopen this.
This minimal example demonstrates this bug:
{{{
from django.db import models
class Poll(models.Model):
question = models.CharField(maxlength=200)
def __str__(self):
return self.question
class Admin:
pass
class Choice(models.Model):
poll = models.ForeignKey(Poll, null=True)
choice = models.CharField(maxlength=200)
def __str__(self):
return self.choice
class Meta:
ordering = ('poll',)
class Admin:
pass
}}}
If you then go to the Admin app index page and click in the Choice link
you get the traceback.
If the patch attached to #2076 gets applied then this ticket may be solved
by making the Admin app stop handling the {{{order_by}}}+foreing key stuff
by itself and leaving the ORM to take care of it. Something like this
small patch:
{{{
--- a/django/contrib/admin/views/main.py.orig 2006-12-30
12:06:18.000000000 -0300
+++ b/django/contrib/admin/views/main.py 2007-02-02 18:00:39.000000000
-0300
@@ -697,17 +697,6 @@
# If the order-by field is a field with a relationship, order by
the
# value in the related table.
lookup_order_field = self.order_field
- try:
- f = self.lookup_opts.get_field(self.order_field,
many_to_many=False)
- except models.FieldDoesNotExist:
- pass
- else:
- if isinstance(f.rel, models.OneToOneRel):
- # For OneToOneFields, don't try to order by the related
object's ordering criteria.
- pass
- elif isinstance(f.rel, models.ManyToOneRel):
- rel_ordering = f.rel.to._meta.ordering and
f.rel.to._meta.ordering[0] or f.rel.to._meta.pk.column
- lookup_order_field = '%s.%s' % (f.rel.to._meta.db_table,
rel_ordering)
# Set ordering.
qs = qs.order_by((self.order_type == 'desc' and '-' or '') +
lookup_order_field)
}}}
Also, ticket #2895 could then also be possibly closed.
--
Ticket URL: <http://code.djangoproject.com/ticket/3002#comment:3>
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
-~----------~----~----~----~------~----~------~--~---