#28335 closed New feature (fixed)
Add query expressions support for models meta ordering
Reported by: | cypreess | Owned by: | Dima Kudosh |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.11 |
Severity: | Normal | Keywords: | model ordering F query expressions |
Cc: | Dima Kudosh | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I am trying to use F() statement inside ordering in model:
class MyModel(models.Model): owner = models.ForeignKey(settings.AUTH_USER_MODEL, blank=True, null=True) created = models.DateTimeField(db_index=True, auto_now_add=True) class Meta: ordering = (F('owner_id').asc(nulls_first=True), 'created')
and this causes an error when running manage.py:
[...] File "/[...]/lib/python3.6/site-packages/django/db/models/base.py", line 1651, in <genexpr> fields = ((f[1:] if f.startswith('-') else f) for f in fields) AttributeError: 'OrderBy' object has no attribute 'startswith'
Change History (3)
comment:1 by , 7 years ago
Cc: | added |
---|---|
Component: | Uncategorized → Database layer (models, ORM) |
Owner: | changed from | to
Status: | new → assigned |
Type: | Uncategorized → New feature |
comment:2 by , 7 years ago
Resolution: | → duplicate |
---|---|
Status: | assigned → closed |
Note:
See TracTickets
for help on using tickets.
Duplicate of #26257