improve admin capabilities

main
eric 2023-11-13 18:17:06 -05:00
parent b055add08d
commit dfd2d8fdf2
2 changed files with 17 additions and 6 deletions

View File

@ -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'<a href="{obj.url}">{obj.url}</a>')

View File

@ -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'''
@ -60,6 +60,9 @@ class Link(models.Model):
self.live = live
super().save(*args, **kwargs)
def get_absolute_url(self):
return reverse("link", args=[self.id])
class Timestamp(models.Model):
''' timestamp of the record returned by doab. records can have multiple timestamps '''