Refs #339 Readonly fields get displayed incorrectly in History view

Instead of passing the Version parameters as initial, override them in the object itself
What I *think* it’s doing is forcing the formset to clear and recreate all the models in the formset on save, rather than updating them in place. I can’t honestly remember what the rational behind this was. Unfortunately, django-reversion has had a history of competing with the django admin to achieve what it wants, with new versions of django breaking past hacks. It’s only in the past couple of django releases that the hacks have stopped breaking, presumably due to the maturity and stability of the django admin.

I’d like to think that there was an easier way to achieve this approach, but I’m also pretty sure that this “kill and recreate” tactic represents the only working solution I could come up with, however hacky and unpleasant.

On 20 Aug 2014, at 17:15, 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)
> 
> That seems like a good idea, I was just toying around with it trying to get a working patch, and I think it would work, however the _hack_inline_formset_initial method is doing some things I don't fully understand. What I'd like to do is, instead of rebuiding the entire Formset from scratch, to only update the objects, and create new forms for the deleted objects.
> 
> for related_version in related_versions.values():
> 
>     
> initial_row = related_version.field_dict
> 
>     
> pk_name = ContentType.objects.get_for_id(related_version.content_type_id).model_class()._meta.pk.name
> 
>     
> del initial_row[pk_name]
> 
>     
> initial.append(initial_row)
> At this point in related_versions there are only left the Versions for which there is no related_obj in the formset queryset, so I guess there are the deleted related object. Then why is it removing the PK?
> 
> Later there are some lines prefixed by Hack the formset to force a save of everything., I see what this is doing, but why?
> 
> —
> Reply to this email directly or view it on GitHub.
>