{{{
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.
* status: new => closed
* version: 3.0 => master
* resolution: => fixed
Comment:
Thanks for this ticket. It was fixed in
013147fae2b9168b06c495aa78c10725cab294cd (I'm not marking this as a
duplicate because it's a different scenario).
--
Ticket URL: <https://code.djangoproject.com/ticket/31481#comment:1>
Comment (by Gergely Kalmár):
Thank you! Am I right that the patch is not released yet? Is there a
workaround (besides patching Django locally) in the meantime?
--
Ticket URL: <https://code.djangoproject.com/ticket/31481#comment:2>
Comment (by felixxm):
> Am I right that the patch is not released yet?
Yes, it's not released. It will be included in Django 3.1.
> Is there a workaround (besides patching Django locally) in the meantime?
You can move `ordering` to the `ExampleExtension`, e.g.
{{{
class ExampleExtension(models.Model):
...
class Meta:
ordering = [models.functions.Lower('example_object__some_field')]
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/31481#comment:3>
Comment (by Gergely Kalmár):
Hm, it seems that Django 3.1 is coming only around August - would that be
possible to move this small patch into a patch release on 3.0 instead? The
workaround doesn't really work that nicely because I need the ordering to
apply also to ExampleObject instances (e.g. for listing) and not only when
using them through ExampleExtension (in this hypothetical case). This
issue keeps breaking the admin interface and it would take quite some work
to work around it in all places I would have to :(.
--
Ticket URL: <https://code.djangoproject.com/ticket/31481#comment:4>