Opened 7 years ago

Last modified 7 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 Tim Graham)

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 Tim Graham, 7 years ago

Cc: Collin Anderson added
Description: modified (diff)
Summary: Model.__repr__ should include the pkModel.__repr__() should include the pk
Type: New featureCleanup/optimization

This is effectively fixed (unless Model.__str__() is overridden) in Django 2.0 by #27953 which includes the pk in the default Model.__str__(). I'm not sure if further changes should be made.

There's some related discussion in #20448.

Note: See TracTickets for help on using tickets.
Back to Top