mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-31 23:16:36 +02:00
Add mixin
This commit is contained in:
parent
e14ebdc2f5
commit
d75742e242
1 changed files with 29 additions and 10 deletions
|
@ -543,7 +543,27 @@ class DomainApplicationAdminForm(forms.ModelForm):
|
||||||
self.fields["status"].widget.choices = available_transitions
|
self.fields["status"].widget.choices = available_transitions
|
||||||
|
|
||||||
|
|
||||||
class DomainApplicationAdmin(ListHeaderAdmin):
|
class OrderableFieldsMixin:
|
||||||
|
orderable_fields = []
|
||||||
|
|
||||||
|
def __new__(cls, *args, **kwargs):
|
||||||
|
new_class = super().__new__(cls)
|
||||||
|
for field, sort_field in cls.orderable_fields:
|
||||||
|
setattr(new_class, f'get_{field}', cls._create_orderable_field_method(field, sort_field))
|
||||||
|
return new_class
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _create_orderable_field_method(cls, field, sort_field):
|
||||||
|
def method(obj):
|
||||||
|
attr = getattr(obj, field)
|
||||||
|
return attr
|
||||||
|
method.__name__ = f'get_{field}'
|
||||||
|
method.admin_order_field = f'{field}__{sort_field}'
|
||||||
|
method.short_description = field.replace('_', ' ').title()
|
||||||
|
return method
|
||||||
|
|
||||||
|
|
||||||
|
class DomainApplicationAdmin(ListHeaderAdmin, OrderableFieldsMixin):
|
||||||
|
|
||||||
"""Custom domain applications admin class."""
|
"""Custom domain applications admin class."""
|
||||||
|
|
||||||
|
@ -553,17 +573,16 @@ class DomainApplicationAdmin(ListHeaderAdmin):
|
||||||
"status",
|
"status",
|
||||||
"organization_type",
|
"organization_type",
|
||||||
"created_at",
|
"created_at",
|
||||||
"submitter",
|
"get_submitter",
|
||||||
"investigator",
|
"get_investigator",
|
||||||
]
|
]
|
||||||
|
|
||||||
def get_requested_domain(self, obj):
|
orderable_fields = [
|
||||||
return obj.requested_domain
|
('requested_domain', 'name'),
|
||||||
get_requested_domain.admin_order_field = 'requested_domain__name' # Allows column order sorting
|
# TODO figure out sorting twice at once
|
||||||
get_requested_domain.short_description = 'Requested Domain' # Sets column's header
|
("submitter", "first_name"),
|
||||||
|
("investigator", "first_name"),
|
||||||
|
]
|
||||||
ordering = ['requested_domain__name']
|
|
||||||
|
|
||||||
# Filters
|
# Filters
|
||||||
list_filter = ("status", "organization_type", "investigator")
|
list_filter = ("status", "organization_type", "investigator")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue