Opened 8 years ago

Closed 6 years ago

#15176 closed New feature (fixed)

History view of AdminSite doesn't take in account user defined queryset

Reported by: Tetsuya Morimoto Owned by: nobody
Component: contrib.admin Version: 1.2
Severity: Normal Keywords: multi-db
Cc: info@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no


I found a bug which does not show history view in AdminSite when I defined a queryset for multi-db.

# see also:

The history_view method of django.contrib.admin.ModelAdmin give a model object to get_object_or_404 as an argument. In that case, normal queryset of the model is used even if user defined custom queryset for the model. It means that the history view isn't showed for multi-db since it define custom queryset.

I made a patch, but I have no idea for making tests code. I only tested after I did some table operation, and I confirmed the history view.

Additionally, you might wonder about the LogEntry(django_admin_log). I think it's no problem since I can handle LogEntry to read/write with db-router.

Attachments (1)

get_history_view_with_user_defined_queryset.patch (661 bytes) - added by Tetsuya Morimoto 8 years ago.
Patch to use self.queryset instead of model

Download all attachments as: .zip

Change History (11)

Changed 8 years ago by Tetsuya Morimoto

Patch to use self.queryset instead of model

comment:1 Changed 8 years ago by Russell Keith-Magee

Component: ORM aggregationdjango.contrib.admin
Needs tests: set
Owner: set to nobody
Triage Stage: UnreviewedAccepted

comment:2 Changed 8 years ago by anonymous

I actually feel divided about this. The history is supposed to show all the things that have been changed/added/deleted in the past. Using a custom queryset means that the history may change over time, which seem kind of weird. I do recognise that there might be cases where we do want a custom queryset to be used, but I also think that in some other cases we might actually want the default one to be used. So I'd be in favour of a more granular system for the history view.

comment:3 Changed 8 years ago by Julien Phalip

Sorry, that was me just above.

comment:4 Changed 8 years ago by Łukasz Rekucki

Severity: Normal
Type: New feature

comment:5 Changed 8 years ago by Jacob

milestone: 1.3

Milestone 1.3 deleted

comment:11 Changed 7 years ago by Aymeric Augustin

UI/UX: unset

Change UI/UX from NULL to False.

comment:12 Changed 7 years ago by Aymeric Augustin

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:13 Changed 6 years ago by Orne Brocaar

I think there might be an other case where it is expected that history_view is using the custom queryset set by the user. I'm currently working on an app where users can only see a subset of data in the admin depending on the groups they are in. By creating a custom queryset method on the ModelAdmin, this works great for listing and editing and I was expected that this would work for history as well (since the history button is visible on item level). However, the user has access to the history of all the items by changing the id in the url.

comment:14 Changed 6 years ago by Orne Brocaar

Cc: info@… added

comment:15 Changed 6 years ago by Julien Phalip

Resolution: fixed
Status: newclosed

This was fixed as part of #21013.

Note: See TracTickets for help on using tickets.
Back to Top