#16760: ORM: Manager.latest() use pk by default
----------------------------+----------------------------------------------
 Reporter:                  |          Owner:  nobody
  freek.wiekmeijer@…        |         Status:  new
     Type:  New feature     |      Component:  Database layer (models, ORM)
Milestone:                  |       Severity:  Normal
  Version:  1.3             |   Triage Stage:  Unreviewed
 Keywords:                  |  Easy pickings:  0
Has patch:  0               |
    UI/UX:  0               |
----------------------------+----------------------------------------------
 This is a proposal for a small improvement in the ORM layer.

 Context:
 The Manager class I'm referring to is django.db.models.manager.Manager. It
 has a public method named latest() which retrieves the most recent record
 from the applicable database table. For example MyModel.objects.latest()
 returns a MyModel object.

 Current behaviour:
 You need to specify which database column to use for the latest() method.
 Either through a Meta class in the model ("get_latest_by" option), or as a
 parameter in the latest() call (i.e. MyModel.objects.latest('id')).

 Suggested change:
 In many situations you just want the object with the highest primary key
 value, which is typically the latest record inserted into the table.
 Change latest() to use the models primary key by default, if no
 "get_latest_by" is specified in the model and no parameter is supplied to
 the method call.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/16760>
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 post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to