mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-04 17:01:56 +02:00
Simplify logic
This commit is contained in:
parent
e5e5fc66e6
commit
dc13fc6661
1 changed files with 8 additions and 4 deletions
|
@ -25,14 +25,18 @@ class OrderableFieldsMixin:
|
|||
"""
|
||||
This magic method is called when a new instance of the class (or subclass) is created.
|
||||
It dynamically adds a new method to the class for each field in `orderable_fk_fields`.
|
||||
Then, it will update the `list_display` attribute such that it uses these generated methods.
|
||||
"""
|
||||
new_class = super().__new__(cls)
|
||||
|
||||
# If the class doesn't define anything for orderable_fk_fields, then we should
|
||||
# just skip this additional logic
|
||||
if not hasattr(cls, "orderable_fk_fields") or len(cls.orderable_fk_fields) == 0:
|
||||
return new_class
|
||||
|
||||
# Check if the list_display attribute exists, and if it does, create a local copy of that list.
|
||||
list_display_exists = hasattr(cls, "list_display")
|
||||
new_list_display = []
|
||||
if list_display_exists and isinstance(cls.list_display, list):
|
||||
new_list_display = cls.list_display.copy()
|
||||
list_display_exists = hasattr(cls, "list_display") and isinstance(cls.list_display, list)
|
||||
new_list_display = cls.list_display.copy() if list_display_exists else []
|
||||
|
||||
for field, sort_field in cls.orderable_fk_fields:
|
||||
updated_name = f"get_{field}"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue