{{{
from django.db import models
# Create your models here.
class Agreement(models.Model):
agreement_id = models.AutoField(verbose_name='ID', serialize=False,
auto_created=True, primary_key=True)
#class Meta:
# generates error in makemigrations
# app.Agreement: (models.E015) 'ordering' refers to the nonexistent
field 'id'.
# ordering = ['id']
class Order(models.Model):
agreement = models.ForeignKey(Agreement, models.DO_NOTHING)
class Meta:
# does not generate error in makemigrations
# but does so during runtime
# e.g. [x for x in Order.objects.all()]
ordering = ['agreement__id']
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29408>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* component: Uncategorized => Database layer (models, ORM)
* version: 2.0 => master
* type: Uncategorized => Cleanup/optimization
* stage: Unreviewed => Accepted
Comment:
I'm going to accept this provisionally. There's
[https://github.com/django/django/blob/2dcc5d629a6439b5547cdd6e67815cabf608fcd4/django/db/models/base.py#L1598-L1600
a `FIXME` in `models/base.py`] specifically about this:
{{{
# Skip ordering in the format field1__field2 (FIXME: checking
# this format would be nice, but it's a little fiddly).
fields = (f for f in fields if LOOKUP_SEP not in f)
}}}
Added in
[https://github.com/django/django/commit/d818e0c9b2b88276cc499974f9eee893170bf0a8
d818e0c9b2b88276cc499974f9eee893170bf0a8].
Either we should address this, or remove the comment and close as
`wontfix` if "fiddly" turns out to be more effort than it's worth.
A test case and a patch showing what "fiddly" actually entails would be
great.
--
Ticket URL: <https://code.djangoproject.com/ticket/29408#comment:1>
Comment (by Windson yang):
I think we can just address this in the document and don't fix it.
--
Ticket URL: <https://code.djangoproject.com/ticket/29408#comment:2>
* cc: Jeff (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/29408#comment:3>
* status: new => assigned
* owner: nobody => Hasan Ramezani
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/29408#comment:4>
* needs_better_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/29408#comment:5>
Comment (by Hasan Ramezani):
patch updated and new method added.
--
Ticket URL: <https://code.djangoproject.com/ticket/29408#comment:6>
* needs_better_patch: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/29408#comment:7>
Comment (by Hasan Ramezani):
Any updates? if there is something to change please inform me. I am ready.
--
Ticket URL: <https://code.djangoproject.com/ticket/29408#comment:8>
* needs_better_patch: 0 => 1
Comment:
Left comments on PR: patch would need to handle JSON paths, which should
be valid in `ordering` since #24747. (Similar issue arises in #29622.)
--
Ticket URL: <https://code.djangoproject.com/ticket/29408#comment:9>
Comment (by Hasan Ramezani):
PR updated. `JSON paths` handled and some tests added for it
--
Ticket URL: <https://code.djangoproject.com/ticket/29408#comment:10>
* needs_better_patch: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/29408#comment:11>
* needs_better_patch: 0 => 1
Comment:
Patch is looking good. There's just a few minor comments on the PR, but
when those are addressed it should be ready to move forwards.
--
Ticket URL: <https://code.djangoproject.com/ticket/29408#comment:12>
* needs_better_patch: 1 => 0
Comment:
Requested changes are done
--
Ticket URL: <https://code.djangoproject.com/ticket/29408#comment:13>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/29408#comment:14>
--
Ticket URL: <https://code.djangoproject.com/ticket/29408#comment:15>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"440505cb2cadbe1a5b9fba246bcde6c04f51d07e" 440505cb]:
{{{
#!CommitTicketReference repository=""
revision="440505cb2cadbe1a5b9fba246bcde6c04f51d07e"
Fixed #29408 -- Added validation of related fields and lookups in model
Meta.ordering.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29408#comment:16>
Comment (by GitHub <noreply@…>):
In [changeset:"f69c7bbdceba43789bfba935dd8fa3daaa7f36c4" f69c7bbd]:
{{{
#!CommitTicketReference repository=""
revision="f69c7bbdceba43789bfba935dd8fa3daaa7f36c4"
Refs #29408 -- Cosmetic edits for validation of related fields and lookups
in model Meta.ordering.
Follow up to 440505cb2cadbe1a5b9fba246bcde6c04f51d07e.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29408#comment:17>