Answer the question
In order to leave comments, you need to log in
How to save change history in Django model?
I'm trying to include the django-reversion
application to save model history . I do according to the documentation and if, save from the administrative interface, then everything works correctly, but no records are made from UpdateView. I'm using Django==1.5.6 and django-reverion==1.7.1.
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.middleware.transaction.TransactionMiddleware',
'reversion.middleware.RevisionMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
# Регистрируем необходимые модели
for report in reports_list():
reversion.register(report)
class ReportUpdate(UpdateView):
...
def post(self, request, *args, **kwargs):
response = super(ReportUpdate, self).post(request, *args, **kwargs)
self.object = self.get_object()
self.object.editor = request.user.profile
self.object.is_filled = True
with transaction.commit_on_success(), reversion.create_revision():
self.object.save()
reversion.set_user(request.user)
reversion.set_comment('comment...')
return response
Answer the question
In order to leave comments, you need to log in
Try like this:
with reversion.create_revision(manage_manually=True):
self.object.save()
reversion.default_revision_manager.save_revision(
[self.object],
user=request.user,
comment='comment...'
)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question