#33678: Admin crash when sorting by a foreign key that's sorted with functions
-----------------------------------------+------------------------
               Reporter:  Eduardo Rivas  |          Owner:  nobody
                   Type:  Uncategorized  |         Status:  new
              Component:  contrib.admin  |        Version:  4.0
               Severity:  Normal         |       Keywords:
           Triage Stage:  Unreviewed     |      Has patch:  0
    Needs documentation:  0              |    Needs tests:  0
Patch needs improvement:  0              |  Easy pickings:  0
                  UI/UX:  0              |
-----------------------------------------+------------------------
 Possibly related to https://code.djangoproject.com/ticket/31481

 {{{
 # models.py
 from django.db import models
 from django.db.models.functions import Lower


 class Material(models.Model):
     code = models.CharField(max_length=255, unique=True)

     class Meta:
         ordering = (Lower("code"),)

     def __str__(self):
         return self.code


 class QuotePartMaterial(models.Model):
     material = models.ForeignKey(Material, on_delete=models.PROTECT)

     def __str__(self):
         return str(self.material)
 }}}


 {{{
 # admin.py
 from django.contrib import admin
 from . import models


 admin.site.register(models.Material)


 @admin.register(models.QuotePartMaterial)
 class QuotePartMaterialAdmin(admin.ModelAdmin):
     list_display = ("material",)
 }}}

 Loading the admin works fine, but If I try to manually sort
 QuotePartMaterial records in the admin by clicking the "Material" column
 header, I get:

 {{{
 FieldError at /admin/example/quotepartmaterial/
 Cannot resolve keyword 'code' into field. Choices are: id, material,
 material_id
 }}}

 Removing the Lower() call on Material.Meta.ordering makes the issue go
 away.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/33678>
Django <https://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 unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/010701808c688be6-dd1db9ed-e819-445c-8e02-be8e88ca4daa-000000%40eu-central-1.amazonses.com.

Reply via email to