From dfd2d8fdf2edb24942c79a7642e8d38950da0040 Mon Sep 17 00:00:00 2001 From: eric Date: Mon, 13 Nov 2023 18:17:06 -0500 Subject: [PATCH] improve admin capabilities --- doab_check/admin.py | 18 +++++++++++++----- doab_check/models.py | 5 ++++- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/doab_check/admin.py b/doab_check/admin.py index 7bb8442..62ab039 100644 --- a/doab_check/admin.py +++ b/doab_check/admin.py @@ -1,4 +1,5 @@ from django.contrib import admin +from django.urls import reverse from django.utils.safestring import mark_safe # Register your models here. @@ -21,23 +22,30 @@ class CheckAdmin(admin.ModelAdmin): class ItemAdmin(admin.ModelAdmin): list_display = (str, 'title', 'resource_type', 'status') date_hierarchy = 'created' - search_fields = ['title'] + search_fields = ['title', 'publisher_name'] @admin.register(models.Link) class LinkAdmin(admin.ModelAdmin): - list_display = ('url', 'provider') + list_display = ('url', 'provider', 'check_status') + list_filter = ['recent_check__return_code'] date_hierarchy = 'created' search_fields = ['url'] - exclude = ['url'] - readonly_fields = ('link_display', 'provider') + exclude = ['url', 'recent_check'] + readonly_fields = ['link_display', 'provider', 'live', 'check_status'] actions = ['recheck'] + @admin.display(description="status") + def check_status(self, obj): + if obj.recent_check: + return str(obj.recent_check.return_code) + @admin.action(description="Recheck the links") def recheck(self, request, queryset): for link in queryset: check_link(link) - + + @admin.display(description="URL") def link_display(self, obj): return mark_safe(f'{obj.url}') diff --git a/doab_check/models.py b/doab_check/models.py index b5d6c69..d33061c 100644 --- a/doab_check/models.py +++ b/doab_check/models.py @@ -2,7 +2,7 @@ from urllib.parse import urlparse from django.db import models - +from django.urls import reverse class Item(models.Model): ''' an object in DOAB''' @@ -59,6 +59,9 @@ class Link(models.Model): break self.live = live super().save(*args, **kwargs) + + def get_absolute_url(self): + return reverse("link", args=[self.id]) class Timestamp(models.Model):