From 3c535f0d5eb827054fb1413b15380145b5514a70 Mon Sep 17 00:00:00 2001 From: Dave Hall Date: Tue, 30 Nov 2010 12:52:03 +0000 Subject: [PATCH] Fixed the problem with reverting file fields in the admin. Finally get to close issue #1 :O https://github.com/etianen/django-reversion/issues#issue/1 --- src/reversion/admin.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/reversion/admin.py b/src/reversion/admin.py index 7a5bbb83..eb722c6c 100644 --- a/src/reversion/admin.py +++ b/src/reversion/admin.py @@ -155,6 +155,10 @@ def render_revision_form(self, request, obj, version, context, revert=False, rec if form.is_valid(): form_validated = True new_object = self.save_form(request, form, change=True) + # HACK: If the value of a file field is None, remove the file from the model. + for field in new_object._meta.fields: + if isinstance(field, models.FileField) and form.cleaned_data[field.name] is None: + setattr(new_object, field.name, None) else: form_validated = False new_object = obj