Changes between Version 1 and Version 2 of Ticket #33258


Ignore:
Timestamp:
Nov 2, 2021, 6:36:37 PM (3 years ago)
Author:
Martin Massera
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #33258 – Description

    v1 v2  
    11In Django's Admin class, most "lists" are initialized as tuples `()` while two of them (`inlines` and `actions`)are initialized as lists `[]`
    22
    3 `
     3{{{
    44list_display = ('__str__',)
    55list_display_links = ()
     
    1212...
    1313actions = []
    14 `
     14}}}
    1515
    1616This is inconsistent.
    1717
    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.
     18And 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.
    1919
    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.
     20ie: 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
     22While lists are more semantically correct than tuples, tuples have the advantage of being immutable, so they force users to reset the value every time.
    2123
    2224So, two solutions:
Back to Top