#31481: Using model functions in model meta ordering fails in admin
-----------------------------------------+------------------------
               Reporter:  GergelyKalmar  |          Owner:  nobody
                   Type:  Bug            |         Status:  new
              Component:  contrib.admin  |        Version:  3.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              |
-----------------------------------------+------------------------
 Let's assume we have two models as follows:

 {{{
 from django.db import models


 class ExampleObject(models.Model):
     some_field = models.CharField(max_length=50)

     class Meta:
         ordering = [models.functions.Lower('some_field')]


 class ExampleExtension(models.Model):
     example_object = models.OneToOneField(
         ExampleObject, primary_key=True, on_delete=models.PROTECT
     )
 }}}

 If I register the latter model in admin:
 {{{
 from django.contrib import admin

 from myapp import models

 admin.site.register(models.ExampleExtension)
 }}}

 I get the following error:
 {{{
 FieldError at /admin/myapp/exampleextension/
 Cannot resolve keyword 'some_field' into field. Choices are:
 example_object, example_object_id
 }}}

 If I remove the `Lower` model function it works as expected. Also, the
 ordering generally seems to work fine in all other places, except in the
 admin interface. Am I doing something silly?

-- 
Ticket URL: <https://code.djangoproject.com/ticket/31481>
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 django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/056.7ce8aa3b1b841947dc1f6024d8e9c9b2%40djangoproject.com.

Reply via email to