Skip to content

Commit

Permalink
Merge pull request #412 from WikipediaLibrary/kgraessle/add-link-even…
Browse files Browse the repository at this point in the history
…ts-to-url-patterns-in-django-admin

This moves the django admin relationship display from LinkEvents to U…
  • Loading branch information
suecarmol authored Dec 13, 2024
2 parents ece86c1 + a425608 commit a29984f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
5 changes: 3 additions & 2 deletions extlinks/aggregates/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class LinkAggregateAdmin(admin.ModelAdmin):
"on_user_list",
)
list_filter = ("organisation", "collection", "month", "year", "on_user_list")
list_select_related = ["organisation", "collection"]


admin.site.register(LinkAggregate, LinkAggregateAdmin)
Expand All @@ -29,7 +30,7 @@ class UserAggregateAdmin(admin.ModelAdmin):
"on_user_list",
)
list_filter = ("organisation", "collection", "month", "year", "on_user_list")

list_select_related = ["organisation", "collection"]

admin.site.register(UserAggregate, UserAggregateAdmin)

Expand All @@ -46,6 +47,6 @@ class PageProjectAggregateAdmin(admin.ModelAdmin):
"on_user_list",
)
list_filter = ("organisation", "collection", "month", "year", "on_user_list")

list_select_related = ["organisation", "collection"]

admin.site.register(PageProjectAggregate, PageProjectAggregateAdmin)
32 changes: 32 additions & 0 deletions extlinks/links/admin.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,35 @@
from django.contrib import admin
from django.contrib.contenttypes.admin import GenericTabularInline

from .models import URLPattern, LinkSearchTotal, LinkEvent


class LinkEventURLPatternAdminInline(GenericTabularInline):
model = LinkEvent
show_change_link = True
exclude = ["user_id", "url"]
readonly_fields = [
"link",
"timestamp",
"domain",
"rev_id",
"page_title",
"page_namespace",
"event_id",
"user_is_bot",
"hash_link_event_id",
"change",
"username",
"on_user_list",
]


class URLPatternAdmin(admin.ModelAdmin):
list_display = ("url",)
exclude = ["collections"]
inlines = [
LinkEventURLPatternAdminInline,
]


admin.site.register(URLPattern, URLPatternAdmin)
Expand All @@ -19,6 +44,13 @@ class LinkSearchTotalAdmin(admin.ModelAdmin):

class LinkEventAdmin(admin.ModelAdmin):
list_display = ("link", "timestamp", "domain", "username", "change")
list_select_related = ["username", "content_type"]
readonly_fields = ["url_pattern_display", "username"]
exclude = ["content_type", "object_id", "url"]

@admin.display(description="URLPattern")
def url_pattern_display(self, instance):
return URLPattern.objects.filter(pk=instance.content_object.pk).first()


admin.site.register(LinkEvent, LinkEventAdmin)
1 change: 1 addition & 0 deletions extlinks/organisations/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class OrganisationAdmin(admin.ModelAdmin):
class CollectionAdmin(admin.ModelAdmin):
list_display = ("name", "organisation")
list_filter = ("name", "organisation")
list_select_related = ["organisation"]


admin.site.register(Collection, CollectionAdmin)

0 comments on commit a29984f

Please sign in to comment.