Django archive user if clicked for detail page view an error appears

so i have this user model and in admin.py which ofcourse is used by my client as admin page view and recently my client requested that the user/s who has been archived should not show in the active list page of in the django admin ,but can be viewed if filtered so i put the functionality in my base "

get_queryset

"

which is as follow

def get_queryset(self, request):
    qs = super().get_queryset(request)

    # detecting if archive date filter is applied
    archive_filter_applied = any(
        key.startswith("archived_at__")
        for key in request.GET
    )

    # default behaviour which excludes archived users
    if not archive_filter_applied:
            qs = qs.filter(archived_at__isnull=True)

    if request.user.is_superuser:
        return qs

    # permission gate
    if not request.user.has_perm("api.view_user"):
        return qs.none()

    therapist_qs = qs.filter(
        Q(treatment_therapist=request.user) |
        Q(assessment_therapist=request.user)
    )

    # data-driven therapist rule
    if therapist_qs.exists():
        return therapist_qs

    return qs

so what happens is as normal the users are shown who are active and not archived but if filter through a filter only those are shown which are archived so till here all is fine but when the archived user is clicked in the list page to see his details page an error appears like this
" Client with ID “375” doesn’t exist. Perhaps it was deleted?"
i have this feeling that i have a bug in this part of code but i cant figure it out

p.s i know the question is long but this the most precise way i could ask

Вернуться на верх