Django

Code

Ticket #9105 (closed: wontfix)

Opened 10 months ago

Last modified 10 months ago

__unicode__ method for models

Reported by: guettli Assigned to: nobody
Milestone: Component: Database layer (models, ORM)
Version: 1.0 Keywords:
Cc: hv@tbz-pariv.de Triage Stage: Design decision needed
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

Hi,

Here is small patch to give models a __unicode__ method which includes its primary key and class name.

Every time I create a new model and look into the admin page (/admin/myapp/mymodel/) I see a list of:

  • MyModel object
  • MyModel object
  • MyModel object

It would be better to have

  • MyModel 1
  • MyModel 2
  • ....

Attachments

model__unicode__method.diff (0.8 kB) - added by guettli on 09/16/08 09:15:46.

Change History

09/16/08 09:15:46 changed by guettli

  • attachment model__unicode__method.diff added.

09/16/08 17:50:48 changed by mattmcc

  • needs_better_patch changed.
  • stage changed from Unreviewed to Design decision needed.
  • needs_tests changed.
  • needs_docs changed.

09/17/08 00:38:49 changed by mtredinnick

  • status changed from new to closed.
  • resolution set to wontfix.

No, this is contrary to how Python normally behaves. You don't get a string-form for free apart form repr() on classes. If you want something different, you define the right method. "Be like Python" is a pretty good guide for this sort of thing. The current default is actually pretty useful: it guides people to immediately think about what they want to have as the default string representation for their particular model.


Add/Change #9105 (__unicode__ method for models)




Change Properties
Action