#28335 closed New feature (fixed)
Add query expressions support for models meta ordering
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 , 8 years ago
Cc: | added |
---|---|
Component: | Uncategorized → Database layer (models, ORM) |
Owner: | changed from | to
Status: | new → assigned |
Type: | Uncategorized → New feature |
comment:2 by , 8 years ago
Resolution: | → duplicate |
---|---|
Status: | assigned → closed |
Note:
See TracTickets
for help on using tickets.
Duplicate of #26257