Skip to content

Instantly share code, notes, and snippets.

@shishirsharma
Last active December 9, 2015 09:51
Show Gist options
  • Save shishirsharma/bbf35599016df0f8c1e2 to your computer and use it in GitHub Desktop.
Save shishirsharma/bbf35599016df0f8c1e2 to your computer and use it in GitHub Desktop.
A brief history of all objects
A brief history of all objects
class SlotCapacityAdmin(reversion.VersionAdmin):
readonly_fields = (slot', 'start_time’, 'end_time’, ‘date’)
#...
import reversion
@reversion.register
class SlotCapacity(models.Model):
slot = models.ForeignKey(Slot, null=True, blank=True)
# ...
reversions = reversion.get_for_object(self)
for reversion in reversions:
if reversion.revision.user:
name = revers.revision.user.first_name + " " + revers.revision.user.last_name
email = revers.revision.user.email
serialized_data = json.loads(reversion.serialized_data)
reversion_data = {}
reversion_data[status] = status
reversion_data[‘slot_id'] = slot_id
# ...
SELECT r.date_created, u.first_name, u.last_name, v.serialized_data
FROM reversion_revision r JOIN auth_user u ON r.user_id=u.id JOIN reversion_version v ON v.revision_id=r.id WHERE v.object_id_int=123456 AND v.content_type_id=78 ORDER BY r.date_created asc;
MIDDLEWARE_CLASSES = (
#...
‘reversion.middleware.RevisionMiddleware’,
#...
)
INSTALLED_APPS = [
#...
‘reversion’
#...
]
pip install django-reversion
reversion_revision
reversion_version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment