Skip to content

Commit a7bc65a

Browse files
chg ! sort in admin
1 parent b1ec4c9 commit a7bc65a

File tree

6 files changed

+11
-13
lines changed

6 files changed

+11
-13
lines changed

src/country_workspace/admin/batch.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class BatchAdmin(BaseModelAdmin):
2222
)
2323
readonly_fields = ("country_office", "program", "imported_by")
2424
search_fields = ("name",)
25+
ordering = ("-import_date",)
2526

2627
def has_add_permission(self, request: HttpRequest) -> bool:
2728
return False

src/country_workspace/admin/rdp.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class RdpAdmin(BaseModelAdmin):
2323
fields = ("name", "country_office", "program", "pushed_by", "push_date", "status", "hope_rdi_id", "related_job")
2424
readonly_fields = ("country_office", "program", "related_job", "push_date", "hope_rdi_id")
2525
search_fields = ("name",)
26+
ordering = ("-push_date",)
2627

2728
def has_add_permission(self, request: HttpRequest) -> bool:
2829
return False

src/country_workspace/models/batch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class BatchSource(models.TextChoices):
1414
country_office = models.ForeignKey("Office", on_delete=models.CASCADE, related_name="%(class)ss")
1515
program = models.ForeignKey("Program", on_delete=models.CASCADE, related_name="%(class)ss")
1616
name = models.CharField(max_length=255, blank=True, null=True)
17-
import_date = models.DateTimeField(auto_now=True)
17+
import_date = models.DateTimeField(auto_now=True, db_index=True)
1818
imported_by = models.ForeignKey(User, on_delete=models.CASCADE)
1919
source = models.CharField(max_length=255, blank=True, null=True, choices=BatchSource.choices)
2020

src/country_workspace/models/rdp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class PushStatus(models.TextChoices):
2020
hope_rdi_id = models.CharField(
2121
max_length=200, null=True, editable=False, help_text=_("RDI unique ID within the HOPE core.")
2222
)
23-
push_date = models.DateTimeField(auto_now=True)
23+
push_date = models.DateTimeField(auto_now=True, db_index=True)
2424
pushed_by = models.ForeignKey(User, on_delete=models.CASCADE)
2525

2626
class Meta:

src/country_workspace/workspaces/admin/batch.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ def queryset(self, request: HttpRequest, queryset: QuerySet) -> QuerySet:
2525

2626
@register(CountryBatch, site=workspace)
2727
class CountryBatchAdmin(SelectedProgramMixin, WorkspaceModelAdmin):
28-
list_display = ["import_date", "name", "imported_by", "source"]
29-
search_fields = ("label",)
28+
list_display = ["name", "import_date", "imported_by", "source"]
29+
search_fields = ("name",)
3030
change_list_template = ["workspace/change_list.html"]
3131
change_form_template = ["workspace/change_form.html"]
32-
ordering = ("name",)
32+
ordering = ("-import_date",)
3333
list_filter = (("source", ChoiceFilter), ("imported_by", UserAutoCompleteFilter))
3434
readonly_fields = fields = ("name", "source")
3535

@@ -38,12 +38,6 @@ def get_common_context(self, request: HttpRequest, pk: str | None = None, **kwar
3838
kwargs["modeladmin_name"] = self.__class__.__name__
3939
return super().get_common_context(request, pk, **kwargs)
4040

41-
def get_search_results(
42-
self, request: HttpRequest, queryset: QuerySet[CountryBatch], search_term: str
43-
) -> tuple[QuerySet[CountryBatch], bool]:
44-
queryset = self.model.objects.filter(program=state.program)
45-
return queryset, False
46-
4741
def get_queryset(self, request: HttpRequest) -> "QuerySet[CountryBatch]":
4842
return (
4943
super()

src/country_workspace/workspaces/admin/rdp.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class CountryRdpAdmin(SelectedProgramMixin, WorkspaceModelAdmin):
2424
search_fields = ("name",)
2525
change_list_template = ["workspace/change_list.html"]
2626
change_form_template = ["workspace/change_form.html"]
27-
ordering = ("name",)
27+
ordering = ("-push_date",)
2828

2929
def has_change_permission(self, request: HttpRequest, obj: CountryRdp | None = None) -> bool:
3030
return False
@@ -40,7 +40,9 @@ def get_common_context(self, request: HttpRequest, pk: str | None = None, **kwar
4040
def related_job(self, obj: CountryRdp) -> str:
4141
if job := obj.jobs.first():
4242
url = reverse("workspace:workspaces_countryasyncjob_change", args=[job.pk])
43-
return format_html('<a href="{}">{}</a>', url, str(job))
43+
return format_html(
44+
'<a href="{}" style="color: var(--link-fg); text-decoration: underline;">{}</a>', url, str(job)
45+
)
4446
return "-"
4547

4648
def get_queryset(self, request: HttpRequest) -> QuerySet[CountryRdp]:

0 commit comments

Comments
 (0)