[Django] #33028: ModelAdmin.init has self.opts, but it still nowerewhere else in django.admin.contrib.options not used

7 views
Skip to first unread message

Django

unread,
Aug 15, 2021, 6:21:03 PM8/15/21
to django-...@googlegroups.com
#33028: ModelAdmin.init has self.opts, but it still nowerewhere else in
django.admin.contrib.options not used
-------------------------------------+-------------------------------------
Reporter: Maxim | Owner: nobody
Danilov |
Type: | Status: new
Uncategorized |
Component: | Version: 3.2
contrib.admin |
Severity: Normal | Keywords: admin, modeladmin
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-------------------------------------+-------------------------------------
At thirst:
{{{
ModelAdmin.__init__():
self.model = model
self.opts = model._meta
}}}

after that i see it more than 40 times in django.admin.contrib.options.py
...
{{{
def __str__(self):
return "%s.%s" % (self.model._meta.app_label,
self.__class__.__name__) # r.n. 593
}}}
...
{{{
info = self.model._meta.app_label, self.model._meta.model_name # r.n. 620
}}}
It's easy to change with find/replace

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

Django

unread,
Aug 15, 2021, 6:22:26 PM8/15/21
to django-...@googlegroups.com
#33028: ModelAdmin.init has self.opts, but it still nowerewhere else in
django.admin.contrib.options not used
-------------------------------------+-------------------------------------
Reporter: Maxim Danilov | Owner: Maxim
Type: | Danilov
Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: 3.2
Severity: Normal | Resolution:

Keywords: admin, modeladmin | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

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

* owner: nobody => Maxim Danilov
* status: new => assigned
* type: Uncategorized => Cleanup/optimization


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

Django

unread,
Aug 17, 2021, 4:42:42 AM8/17/21
to django-...@googlegroups.com
#33028: ModelAdmin.init has self.opts, but it still nowerewhere else in
django.admin.contrib.options not used
-------------------------------------+-------------------------------------
Reporter: Maxim Danilov | Owner: Maxim
Type: | Danilov
Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: 3.2
Severity: Normal | Resolution:
Keywords: admin, modeladmin | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

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

* stage: Unreviewed => Accepted


Comment:

Hi Maxim.

I'll provisionally accept this for review. Let's see what the cleanup
looks like.

This have been the same for a long time. (e.g. Many of the lines are
unchanged since a19ed8aea395e8e07164ff7d85bd7dff2f24edca.) We can't change
the API here, and it might be that it's not worth it looking at the diff,
but in principle yes, a bit more consistency of usage might make it easier
to follow.

Thanks

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

Django

unread,
Dec 14, 2021, 12:46:18 PM12/14/21
to django-...@googlegroups.com
#33028: ModelAdmin.init has self.opts, but it still nowerewhere else in
django.admin.contrib.options not used
-------------------------------------+-------------------------------------
Reporter: Maxim Danilov | Owner: Marcelo
Type: | Galigniana

Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: 3.2
Severity: Normal | Resolution:
Keywords: admin, modeladmin | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

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

* owner: Maxim Danilov => Marcelo Galigniana


Comment:

Hello!

I can do the find/replace to see how the diff looks like.

But I would suggest to do the opposite way: remove the use of `self.opts`
and use `._meta` instead (which in my opinion it's easier; at least to get
more consistency). What do you think?

I did a quick search in my local project and I got:

- For ".opts" -> **66** results in **11** files
- For "model._meta" -> **980** results in **134** files
- And just "._meta" -> **2215** results in **225** files

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

Django

unread,
Dec 14, 2021, 2:47:00 PM12/14/21
to django-...@googlegroups.com
#33028: ModelAdmin.init has self.opts, but it still nowerewhere else in
django.admin.contrib.options not used
-------------------------------------+-------------------------------------
Reporter: Maxim Danilov | Owner: Maxim
Type: | Danilov
Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: 3.2
Severity: Normal | Resolution:
Keywords: admin, modeladmin | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

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

* owner: Marcelo Galigniana => Maxim Danilov


Comment:

Hi Marcelo.
If i use ModelAdmin.opts, i use public Attribute from instance and i can
override it for my needs.
i think it is right.

If in ModelAdmin placed self.model._meta, at first it is wrong to use
privat property from other object, at second - it is possible, but more
difficult to override it.

That's why i see ModelAdmin.opts is a right way for Django.

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

Django

unread,
Dec 14, 2021, 3:44:49 PM12/14/21
to django-...@googlegroups.com
#33028: ModelAdmin.init has self.opts, but it still nowerewhere else in
django.admin.contrib.options not used
-------------------------------------+-------------------------------------
Reporter: Maxim Danilov | Owner: Maxim
Type: | Danilov
Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: 3.2
Severity: Normal | Resolution:
Keywords: admin, modeladmin | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

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

Comment (by Marcelo Galigniana):

Thank you for the explanation Maxim! And sorry again!

Replying to [comment:4 Maxim Danilov]:


> Hi Marcelo.
> If i use ModelAdmin.opts, i use public Attribute from instance and i can
override it for my needs.
> i think it is right.
>
> If in ModelAdmin placed self.model._meta, at first it is wrong to use
privat property from other object, at second - it is possible, but more
difficult to override it.
>
> That's why i see ModelAdmin.opts is a right way for Django.
>
>

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

Django

unread,
Jun 15, 2022, 3:57:20 AM6/15/22
to django-...@googlegroups.com
#33028: ModelAdmin.init has self.opts, but it still nowerewhere else in
django.admin.contrib.options not used
--------------------------------------+------------------------------------
Reporter: Maxim Danilov | Owner: (none)
Type: Cleanup/optimization | Status: new

Component: contrib.admin | Version: 3.2
Severity: Normal | Resolution:
Keywords: admin, modeladmin | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

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

* owner: Maxim Danilov => (none)
* status: assigned => new


--
Ticket URL: <https://code.djangoproject.com/ticket/33028#comment:6>

Django

unread,
Jun 15, 2022, 2:31:48 PM6/15/22
to django-...@googlegroups.com
#33028: ModelAdmin.init has self.opts, but it still nowerewhere else in
django.admin.contrib.options not used
-------------------------------------+-------------------------------------
Reporter: Maxim Danilov | Owner: Marcelo
Type: | Galigniana
Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: 3.2
Severity: Normal | Resolution:
Keywords: admin, modeladmin | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

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

* owner: (none) => Marcelo Galigniana


* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/33028#comment:7>

Django

unread,
Jun 20, 2022, 2:17:25 PM6/20/22
to django-...@googlegroups.com
#33028: ModelAdmin.init has self.opts, but it still nowerewhere else in
django.admin.contrib.options not used
-------------------------------------+-------------------------------------
Reporter: Maxim Danilov | Owner: Marcelo
Type: | Galigniana
Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: 3.2
Severity: Normal | Resolution:
Keywords: admin, modeladmin | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

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

* has_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/33028#comment:8>

Django

unread,
Jun 20, 2022, 5:00:21 PM6/20/22
to django-...@googlegroups.com
#33028: ModelAdmin.init has self.opts, but it still nowerewhere else in
django.admin.contrib.options not used
-------------------------------------+-------------------------------------
Reporter: Maxim Danilov | Owner: Marcelo
Type: | Galigniana
Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: 3.2
Severity: Normal | Resolution:
Keywords: admin, modeladmin | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

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

Comment (by Marcelo Galigniana):

[https://github.com/django/django/pull/15782 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/33028#comment:9>

Django

unread,
Jun 21, 2022, 2:02:32 AM6/21/22
to django-...@googlegroups.com
#33028: ModelAdmin.init has self.opts, but it still nowerewhere else in
django.admin.contrib.options not used
-------------------------------------+-------------------------------------
Reporter: Maxim Danilov | Owner: Marcelo
Type: | Galigniana
Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: 3.2
Severity: Normal | Resolution:
Keywords: admin, modeladmin | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/33028#comment:10>

Django

unread,
Jun 21, 2022, 8:28:08 PM6/21/22
to django-...@googlegroups.com
#33028: ModelAdmin.init has self.opts, but it still nowerewhere else in
django.admin.contrib.options not used
-------------------------------------+-------------------------------------
Reporter: Maxim Danilov | Owner: Marcelo
Type: | Galigniana
Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: 3.2
Severity: Normal | Resolution:
Keywords: admin, modeladmin | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

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

* needs_better_patch: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/33028#comment:11>

Django

unread,
Jun 22, 2022, 1:58:52 AM6/22/22
to django-...@googlegroups.com
#33028: ModelAdmin.init has self.opts, but it still nowerewhere else in
django.admin.contrib.options not used
-------------------------------------+-------------------------------------
Reporter: Maxim Danilov | Owner: Marcelo
Type: | Galigniana
Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: 3.2
Severity: Normal | Resolution:
Keywords: admin, modeladmin | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

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

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/33028#comment:12>

Django

unread,
Jun 22, 2022, 3:45:22 AM6/22/22
to django-...@googlegroups.com
#33028: ModelAdmin.init has self.opts, but it still nowerewhere else in
django.admin.contrib.options not used
-------------------------------------+-------------------------------------
Reporter: Maxim Danilov | Owner: Marcelo
Type: | Galigniana
Cleanup/optimization | Status: closed
Component: contrib.admin | Version: 3.2
Severity: Normal | Resolution: fixed

Keywords: admin, modeladmin | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"d80a2585532ef15184afed6cf4ec1358198a894d" d80a2585]:
{{{
#!CommitTicketReference repository=""
revision="d80a2585532ef15184afed6cf4ec1358198a894d"
Fixed #33028 -- Used ModelAdmin's opts attribute instead of model._meta.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/33028#comment:13>

Reply all
Reply to author
Forward
0 new messages