Refs #339 Readonly fields get displayed incorrectly in History view

Instead of passing the Version parameters as initial, override them in the object itself
I’m utterly unconcerned with optimisation at this level!

My concern was with the correctness of your code, but I see that I was mistaken. I see no reason not to include this pull request, but I’ll review some of the past attempts first to make sure this isn’t doing something that has been proven broken before. (There has been another attempt at this feature that DID introduce a bug, so I need to check).

On 19 Aug 2014, at 16:04, Diego Gaustein <notifications@github.com> wrote:

> In src/reversion/admin.py:
> 
> > @@ -323,7 +323,12 @@ def render_revision_form(self, request, obj, version, context, revert=False, rec
> >              # change_view.  Once again, a hook for this kind of functionality
> >              # would be nice.  Unfortunately, it results in doubling the number
> >              # of queries required to construct the formets.
> > -            form = ModelForm(instance=obj, initial=self.get_revision_form_data(request, obj, version))
> > +            initial = self.get_revision_form_data(request, obj, version)
> > +            for key, value in initial.items():
> > +                field = model._meta.get_field(key)
> > +                setattr(obj, field.attname, value)
> 
> A possible optimization would be
> 
> initial = self.get_revision_form_data(request, obj, version)
> for key, value in initial.items():
> 
>     
> try:
> 
>         
> setattr(obj, key, value)
> 
>     
> except ValueError:
> 
>         
> field = model._meta.get_field(key)
> 
>         
> setattr(obj, field.attname, value)
> It is slightly more expensive if the model has a lot of ForeignKeys, but it avoids the overhead of get_field() for all other field types. Would you prefer this?
> 
> —
> Reply to this email directly or view it on GitHub.
>