[Django] #31434: Enhancement in the default __str__() function.

4 views
Skip to first unread message

Django

unread,
Apr 7, 2020, 11:03:36 AM4/7/20
to django-...@googlegroups.com
#31434: Enhancement in the default __str__() function.
-------------------------------------+-------------------------------------
Reporter: Chinmoy | Owner: Chinmoy
Type: | Status: assigned
Uncategorized |
Component: Database | Version: 3.0
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
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)> ]>

----

--
Ticket URL: <https://code.djangoproject.com/ticket/31434>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Apr 7, 2020, 11:05:23 AM4/7/20
to django-...@googlegroups.com
#31434: Enhancement in the default __str__() function.
-------------------------------------+-------------------------------------
Reporter: Chinmoy | Owner: Chinmoy
Type: Uncategorized | Status: assigned
Component: Database layer | Version: 3.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Chinmoy):

* Attachment "modelpreview.png" added.

An example screenshot of the str() output

Django

unread,
Apr 7, 2020, 4:22:19 PM4/7/20
to django-...@googlegroups.com
#31434: Enhancement in the default __str__() function.
-------------------------------------+-------------------------------------
Reporter: Chinmoy | Owner: Chinmoy
Type: New feature | Status: closed

Component: Database layer | Version: 3.0
(models, ORM) |
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* status: assigned => closed
* type: Uncategorized => New feature
* resolution: => wontfix


Old description:

> 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)> ]>
>
> ----

New description:

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)> ]>
}}}

--

Comment:

> 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 [https://groups.google.com/forum/#!msg/django-
developers/7Jqzwg5nt-c/hY7KtxkfooMJ the mailing list] and IMO is useful in
most of cases. You can refresh a discussion on DevelopersMailingList if
you don't agree.

--
Ticket URL: <https://code.djangoproject.com/ticket/31434#comment:1>

Reply all
Reply to author
Forward
0 new messages