Hi Karen, could you point me to the code in admin which is responsible for this behaviour? I could produce a patch, do some testing and submit a ticket.
Thank you On Mon, Jun 30, 2008 at 9:29 PM, Karen Tracey <[EMAIL PROTECTED]> wrote: > On Mon, Jun 30, 2008 at 11:32 AM, Alex Rades <[EMAIL PROTECTED]> wrote: > >> Hi, >> In the admin site (using latest newforms-admin), it seems not possible to >> sort a table by a ForeignKey which is blank=True, null=True. >> See this little example: >> >> class Group(models.Model): >> name = models.CharField(max_length=200, primary_key=True) >> >> class Person(models.Model): >> name = models.CharField(max_length=200, primary_key=True) >> group = models.ForeignKey(Group, blank=True, null=True) >> >> Is there a valid reason for this limitation? At least on pgsql sorting by >> a nullable field is perfectly valid. > > > Looking at the source code history, the lines of code that prevent > null=True ForeignKey columns in a change list table from being sortable > appears to have been there since the dawn of time. So it's an old > restriction with no ticket to refer to to see why it was added. > > However, I know that prior to queryset-refactor ordering by foreign key > fields was notoriously fragile. I think you needed to ensure > select_related() was used on the QuerySet to force the join to the related > table, but select_related() would not follow null=True ForeignKeys so trying > to oder by a null=True ForeignKey probably just did not work or possibly > dropped results from the list due to an inner join being used. As recently > as last week there were still problems with this exact scenario (see > http://code.djangoproject.com/ticket/7181). > > Assuming all such problems have all been fixed now, though, it would seem > this restriction could be removed from admin. I did some experimenting and > if I remove the code in admin that prevents such sorting, everything seems > to work. I tried with sqlite, mysql, and postgres backends and included > records with null values in my tests. > > Anyone else know any reason why this restriction should be maintained? So > far as I can tell if the base queryset code now supports this kind of > ordering admin ought to take advantage of it? > > Karen > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---