Question

I have a list of documents. On the view of each document instance I'd like to highlight prior versions of the same document. I want to show how the document has changed over time, and my idea was to always compare each version to the one that came before it. So, for example, compare version 2 to version 1. And highlight what changed.

To solve this problem, I would like to find out how I could compare two model instances and return a key/value list of differences.

Was it helpful?

Solution

The answer to your question is pretty much contained in this Stackoverflow question.

Iterate over model instance field names and values in template

Once you have extracted the field names it should be pretty simple to iterate over them, using getattr() to extract the data values from the two different record versions. After that it's just a matter of formatting to taste.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top