mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-16 01:27:03 +02:00
Add descriptive subheader for listing pages in django admin
This commit is contained in:
parent
d506e5a8e8
commit
eac616204b
3 changed files with 48 additions and 2 deletions
|
@ -140,6 +140,26 @@ class DomainApplicationAdmin(AuditedAdmin):
|
|||
else:
|
||||
# Regular users can only view the specified fields
|
||||
return self.readonly_fields
|
||||
|
||||
def changelist_view(self, request, extra_context=None):
|
||||
if extra_context is None:
|
||||
extra_context = {}
|
||||
# Get the filtered values
|
||||
filters = self.get_filters(request)
|
||||
# Pass the filtered values to the template context
|
||||
extra_context['filters'] = filters
|
||||
extra_context['search_query'] = request.GET.get('q', '') # Assuming the search query parameter is 'q'
|
||||
return super().changelist_view(request, extra_context=extra_context)
|
||||
|
||||
def get_filters(self, request):
|
||||
filters = []
|
||||
# Retrieve the filter parameters
|
||||
for param in request.GET.keys():
|
||||
# Exclude the default search parameter 'q'
|
||||
if param != 'q' and param != 'o':
|
||||
# Append the filter parameter and its value to the list
|
||||
filters.append({'parameter_name': param.replace('__exact','').replace('_type','').replace('__id',' id'), 'parameter_value': request.GET.get(param)})
|
||||
return filters
|
||||
|
||||
|
||||
admin.site.register(models.User, MyUserAdmin)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue