Opened 4 years ago

Closed 4 years ago

#31434 closed New feature (wontfix)

Enhancement in the default __str__() function.

Reported by: Chinmoy Owned by: Chinmoy
Component: Database layer (models, ORM) Version: 3.0
Severity: Normal Keywords:
Cc: 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 Mariusz Felisiak)

The default __str__() function provides a rather impractical output and almost every time the developer has to change it to get the summary of the model. I suggest a more elaborate default __str__() function which outputs the field names with their datatypes(A skeletal schema). Maybe it could also print the complete data with the field name and their values?
This is an example of what it could output.

<QuerySet [
<Question: (<django.db.models.fields.AutoField: id>, <django.db.models.fields.CharField: question_text>, <django.db.models.fields.DateTimeField: pub_date>) object (1)>  ]>

Attachments (1)

modelpreview.png (20.6 KB ) - added by Chinmoy 4 years ago.
An example screenshot of the str() output

Download all attachments as: .zip

Change History (2)

by Chinmoy, 4 years ago

Attachment: modelpreview.png added

An example screenshot of the str() output

comment:1 by Mariusz Felisiak, 4 years ago

Description: modified (diff)
Resolution: wontfix
Status: assignedclosed
Type: UncategorizedNew feature

The default __str__() function provides a rather impractical output and almost every time the developer has to change it to get the summary of the model.

I don't agree. The current implementation is the result of consensus reached on the mailing list and IMO is useful in most of cases. You can refresh a discussion on DevelopersMailingList if you don't agree.

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