I'm using what the django-reversion documents call the low-level API in order to access the reversion history in my own code, apart from the admin. To store metadata, I've extended the Revision
model by setting up my own model including a OneToOneField(Revision)
. So far, so good.
But given that reference to a Revision
, how can I access the revision directly before it? For example, to generate a list of changes between this revision and the previous one, is there any more efficient method than calling back to reversion.get_for_object
and searching the list for the version I'm looking for?
The Revision object has a
date_created
attribute, so you could write a query to select the single most recent revision for your object prior to the given revision'sdate_created
. I'd basically copy the implementation of the low-level API'sget_for_date
function, with one change -- use"date_created__lt"
instead of"__lte"
: