3

I am using django-reversion. How can I print all revisions in every model in a ListView?

I've tried

class RevisionListView(ListView):
    model = reversion.revisions.Version
    template_name = "revision_list.html"

and printing the queryset in my template with

{% for version in version_list %}
    {{ version }}
{% endfor %}

It seems to work but I don't know how to get the link to the 'original object' (through get_absolute_url). It seems that I get object_id and content_type but I don't know how to get the object's absolute url defined in models.py.

Can I print the number of revision and what number the specific revision is among the revision for the specific object?

I've searched through SO as I thought others have had the same problem but I cannot find anything.

Jamgreen
  • 10,329
  • 29
  • 113
  • 224

1 Answers1

0

Did you ever figure this out? Reversion does it internally by doing this:

def history_view(self, request, object_id, extra_context=None):
    """Renders the history view."""
    # check if user has change or add permissions for model
    if not self.has_change_permission(request):
        raise PermissionDenied
    object_id = unquote(object_id) # Underscores in primary key get quoted to "_5F"
    opts = self.model._meta
    action_list = [
        {
            "revision": version.revision,
            "url": reverse("%s:%s_%s_revision" % (self.admin_site.name, opts.app_label, opts.module_name), args=(quote(version.object_id), version.id)),
        }
        for version
        in self._order_version_queryset(self.revision_manager.get_for_object_reference(
            self.model,
            object_id,
        ).select_related("revision__user"))
    ]
    # Compile the context.
    context = {"action_list": action_list}
    context.update(extra_context or {})
    return super(VersionAdmin, self).history_view(request, object_id, context)
A G
  • 997
  • 2
  • 18
  • 36