Changes between Version 1 and Version 2 of Ticket #33258
- Timestamp:
- Nov 2, 2021, 6:36:37 PM (3 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #33258 – Description
v1 v2 1 1 In Django's Admin class, most "lists" are initialized as tuples `()` while two of them (`inlines` and `actions`)are initialized as lists `[]` 2 2 3 ` 3 {{{ 4 4 list_display = ('__str__',) 5 5 list_display_links = () … … 12 12 ... 13 13 actions = [] 14 ` 14 }}} 15 15 16 16 This is inconsistent. 17 17 18 And also there is a Since these are declared in the class, they are shared among all instances if this value is not set.18 And also since these are declared in the class, they are shared among all instances if this value is not set. This brings the problem where you inadvertedly add a value to a list and this gets added to all Admin instances where this attribute has not been set. 19 19 20 I wanted to add an action to an admin subclass so I did `MyAdmin.actions.append('some_action')` which added this action to all my admins who had not set a new value to `actions`. While lists are more semantically correct than tuples, tuples have the advantage of being immutable, so they force users to reset the value every time. 20 ie: I wanted to add an action to an admin subclass so I did `MyAdmin.actions.append('some_action')` which added this action to all my admins who had not set a new value to `actions`. 21 22 While lists are more semantically correct than tuples, tuples have the advantage of being immutable, so they force users to reset the value every time. 21 23 22 24 So, two solutions: