Skip to content

Commit

Permalink
Merge pull request #4611 from freelawproject/4602-pghistorys-event-ad…
Browse files Browse the repository at this point in the history
…min-page-for-a-single-object-never-loads

Fix event admin page for pghistory
  • Loading branch information
quevon24 authored Nov 4, 2024
2 parents 505270e + caf9639 commit d64017c
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion cl/settings/third_party/pghistory.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# Default pghistory trackers for @pghistory.track()
import pghistory
from django.apps import apps
from pghistory.admin.core import (
BackFilter,
EventModelFilter,
LabelFilter,
MethodFilter,
ObjFilter,
)
from pghistory.config import admin_model


class EventsAdminNoFilters(pghistory.admin.EventsAdmin):
Expand All @@ -31,7 +32,21 @@ def get_list_filter(self, request):

return filters

def get_queryset(self, request):
# Run query only when we have a model name and object id in url. e.g.
# obj=search.RECAPDocument:372557163
if "obj" in request.GET and ":" in request.GET.get("obj", ""):
model_name, obj_id = request.GET["obj"].split(":")
model_class = apps.get_model(model_name)
return admin_model().objects.tracks(
model_class.objects.get(id=obj_id)
)

# By default it wont perform any query
return admin_model().objects.none()


# Default pghistory trackers for @pghistory.track()
PGHISTORY_DEFAULT_TRACKERS = (
pghistory.UpdateEvent(
condition=pghistory.AnyChange(exclude_auto=True), row=pghistory.Old
Expand Down

0 comments on commit d64017c

Please sign in to comment.