Opened 8 years ago
Last modified 8 years ago
#28839 closed Cleanup/optimization
Model.__repr__() should include the pk — at Version 1
| Reported by: | Álex Córcoles | Owned by: | nobody | 
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | 1.11 | 
| Severity: | Normal | Keywords: | |
| Cc: | Collin Anderson | Triage Stage: | Unreviewed | 
| Has patch: | no | Needs documentation: | no | 
| Needs tests: | no | Patch needs improvement: | no | 
| Easy pickings: | no | UI/UX: | no | 
Description (last modified by )
This was proposed on https://code.djangoproject.com/ticket/1055 , but it was fixed without including the PK. It was also suggested in https://code.djangoproject.com/ticket/20448 , but ignored.
I think the PK is very valuable as __repr__, as it allows you to retrieve the object unambiguously; while str really can't have a good default implementation.
Change History (1)
comment:1 by , 8 years ago
| Cc: | added | 
|---|---|
| Description: | modified (diff) | 
| Summary: | Model.__repr__ should include the pk → Model.__repr__() should include the pk | 
| Type: | New feature → Cleanup/optimization | 
  Note:
 See   TracTickets
 for help on using tickets.
    
This is effectively fixed (unless
Model.__str__()is overridden) in Django 2.0 by #27953 which includes the pk in the defaultModel.__str__(). I'm not sure if further changes should be made.There's some related discussion in #20448.