question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

View deleted instances from admin page

See original GitHub issue

The SimpleHistoryAdmin allows the history of a instance that still exists to bee seen. It would be great if there would be a way to view a list of deleted instances, and see their histories.

Issue Analytics

  • State:open
  • Created 10 years ago
  • Reactions:4
  • Comments:14 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
rhavercommented, Apr 9, 2022

Collating the snippets by @marco-silva0000, you can define a new admin type SimpleHistoryWithDeletedAdmin. Any model admin class that derives from it includes the filter that lists deleted objects.

from django.contrib import admin
from django.contrib.admin.utils import quote
from django.urls import reverse
from simple_history.admin import SimpleHistoryAdmin

class SimpleHistoryWithDeletedAdmin(SimpleHistoryAdmin):
  class SimpleHistoryShowDeletedFilter(admin.SimpleListFilter):
    title = "Entries"
    parameter_name = "entries"

    def lookups(self, request, model_admin):
      return (
        ("deleted_only", "Only Deleted"),
      )

    def queryset(self, request, queryset):
      if self.value():
        return queryset.model.history.filter(history_type='-').distinct()
      return queryset

  def get_changelist(self, request, **kwargs):
    def url_from_result_maker(history=False):
      def custom_url_for_result(self, result):
        pk = getattr(result, self.pk_attname)
        route_type = 'history' if history else 'change'
        route = f'{self.opts.app_label}_{self.opts.model_name}_{route_type}'
        return reverse(f'admin:{route}',
                       args=(quote(pk),),
                       current_app=self.model_admin.admin_site.name)
      return custom_url_for_result
    
    changelist = super().get_changelist(request, **kwargs)
    if request.GET.get('entries', None) == 'deleted_only':
      changelist.url_for_result = url_from_result_maker(history=True)
    else:
      changelist.url_for_result = url_from_result_maker(history=False)
    return changelist
  
  def get_list_filter(self, request):
    return [self.SimpleHistoryShowDeletedFilter] + [
      f for f in super().get_list_filter(request)
    ]
1reaction
Visgeancommented, Jun 13, 2017

Any progress on this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

View deleted instances from admin page · Issue #72 - GitHub
As a PoC or a workaround I've created a django filter that will list the deleted entries. note that if you are using...
Read more >
Recreate or restore a terminated Amazon EC2 instance
It's not possible to recover either the original Amazon EC2 instance or any volumes that were deleted as part of the termination process....
Read more >
Deleted Admin Role from personal instance... - ServiceNow
Solved: Total newbie mistake - I'm pretty sure I deleted the Admin Role in my instance ( https://dev21942.service-now.com ) while intending to delete....
Read more >
Deleting process instances - IBM
Also, if a delete operation takes a long time, you can get a count to check how many instances are remaining to be...
Read more >
Method: users.undelete | Admin console - Google Developers
Method: users.undelete ... Undeletes a deleted user. HTTP request. POST https://admin.googleapis.com/admin/directory/v1/users ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found