-
-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4577 from freelawproject/pghistory_admin_page
feat(pghistory): enable Events admin for single object's history
- Loading branch information
Showing
2 changed files
with
37 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,45 @@ | ||
# Default pghistory trackers for @pghistory.track() | ||
import pghistory | ||
from pghistory.admin.core import ( | ||
BackFilter, | ||
EventModelFilter, | ||
LabelFilter, | ||
MethodFilter, | ||
ObjFilter, | ||
) | ||
|
||
|
||
class EventsAdminNoFilters(pghistory.admin.EventsAdmin): | ||
"""Disable filters, except when looking at the events of a single object. | ||
In combination with `PGHISTORY_ADMIN_ALL_EVENTS = False` | ||
it causes the Events admin page to make no queries, except | ||
when looking at a single object's history, preventing | ||
useless DB hits | ||
""" | ||
|
||
def get_list_filter(self, request): | ||
filters = [] | ||
if "obj" in request.GET: | ||
filters = [ | ||
LabelFilter, | ||
EventModelFilter, | ||
MethodFilter, | ||
ObjFilter, | ||
BackFilter, | ||
] | ||
|
||
return filters | ||
|
||
|
||
PGHISTORY_DEFAULT_TRACKERS = ( | ||
pghistory.UpdateEvent( | ||
condition=pghistory.AnyChange(exclude_auto=True), row=pghistory.Old | ||
), | ||
pghistory.DeleteEvent(), | ||
) | ||
|
||
# Disable the page with all Pghistory events, this page | ||
# will only be viewable with filters | ||
PGHISTORY_ADMIN_ALL_EVENTS = False | ||
PGHISTORY_ADMIN_CLASS = EventsAdminNoFilters |