[Django] #30794: Automatic solution for “Add a related_name argument to the definition for 'XXX'.” for inspectdb.py

18 views
Skip to first unread message

Django

unread,
Sep 22, 2019, 2:24:14 PM9/22/19
to django-...@googlegroups.com
#30794: Automatic solution for “Add a related_name argument to the definition for
'XXX'.” for inspectdb.py
-------------------------------------+-------------------------------------
Reporter: | Owner: nobody
mingwugmail |
Type: | Status: new
Uncategorized |
Component: Database | Version: 2.2
layer (models, ORM) |
Severity: Normal | Keywords: related_name
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
https://stackoverflow.com/a/52872876

the solution is here:

#Original inspectdb
121 if rel_to in known_models:
122 field_type = 'ForeignKey(%s' % rel_to
123 else:
124 field_type = "ForeignKey('%s'" %
rel_to

#Modified inspectdb
121 if rel_to in known_models:
122 field_type = 'ForeignKey(%s' % rel_to
123 else:
124 field_type = "ForeignKey('%s'" %
rel_to
125 extra_params["related_name"] = '%s_%s' %
(table2model(table_name),column_to_field_name[column_name])


to be added to:

https://github.com/django/django/blob/master/django/core/management/commands/inspectdb.py#L131

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

Django

unread,
Sep 22, 2019, 2:58:14 PM9/22/19
to django-...@googlegroups.com
#30794: Automatic solution for “Add a related_name argument to the definition for
'XXX'.” for inspectdb.py
-------------------------------------+-------------------------------------
Reporter: mingwugmail | Owner: nobody
Type: Uncategorized | Status: new
Component: Database layer | Version: 2.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: related_name | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Claude Paroz):

I'm not sure it is a change wanted by everyone. This can save some work in
some configurations, and add a burden in other situations where the user
don't need nor want to have related_name set.

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

Django

unread,
Sep 23, 2019, 2:05:07 AM9/23/19
to django-...@googlegroups.com
#30794: Automatic solution for “Add a related_name argument to the definition for
'XXX'.” for inspectdb.py.

-------------------------------------+-------------------------------------
Reporter: mingwugmail | Owner: nobody
Type: New feature | Status: closed
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: duplicate

Keywords: related_name | 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: new => closed
* type: Uncategorized => New feature
* version: 2.2 => master
* resolution: => duplicate


Comment:

Duplicate of #11179.

--
Ticket URL: <https://code.djangoproject.com/ticket/30794#comment:2>

Django

unread,
Sep 23, 2019, 2:06:28 AM9/23/19
to django-...@googlegroups.com
#30794: inspectdb should generate related_name for ForeignKey.

-------------------------------------+-------------------------------------
Reporter: mingwugmail | Owner: nobody
Type: New feature | Status: closed
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: duplicate
Keywords: related_name | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

--
Ticket URL: <https://code.djangoproject.com/ticket/30794#comment:3>

Django

unread,
Sep 23, 2019, 1:38:43 PM9/23/19
to django-...@googlegroups.com
#30794: inspectdb should generate related_name for ForeignKey.
-------------------------------------+-------------------------------------
Reporter: mingwugmail | Owner: nobody
Type: New feature | Status: new

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

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

* status: closed => new
* resolution: duplicate =>


Comment:

Well, the problem is the models.py is generated by the utility `python
manage.py inspectdb`, then when it's loaded e.g. `python manage.py
runserver`, the system report hundreds of such errors.

If you think this feature may not be needed by everyone, at least add an
option for people who *actually* need it; otherwise, these users have to
do hundreds of modification on the *generated* file.

--
Ticket URL: <https://code.djangoproject.com/ticket/30794#comment:4>

Django

unread,
Sep 23, 2019, 2:02:22 PM9/23/19
to django-...@googlegroups.com
#30794: inspectdb should generate related_name for ForeignKey.
-------------------------------------+-------------------------------------
Reporter: mingwugmail | Owner: nobody
Type: New feature | Status: closed

Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: duplicate

Keywords: related_name | 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: new => closed

* resolution: => duplicate


Comment:

Please don't reopen tickets closed as duplicates. You can leave your
comments in the original ticket but also don't reopen it.
[https://docs.djangoproject.com/en/stable/internals/contributing/triaging-
tickets/#closing-tickets Follow triaging guidelines with regards to
wontfix tickets.]

--
Ticket URL: <https://code.djangoproject.com/ticket/30794#comment:5>

Reply all
Reply to author
Forward
0 new messages