diff --git a/sourcing/model.py b/sourcing/model.py
index 0a3cb35..8ff3ec4 100644
--- a/sourcing/model.py
+++ b/sourcing/model.py
@@ -162,7 +162,7 @@ class Item(TimeStampedModel):
return url_for('.view_item',
username=self.user.username,
hashid=self.hashid,
- v=version.transaction_id)
+ v=version)
@property
def history_url(self):
diff --git a/sourcing/templates/history.html b/sourcing/templates/history.html
index b4cfe05..3e5bf75 100644
--- a/sourcing/templates/history.html
+++ b/sourcing/templates/history.html
@@ -28,7 +28,7 @@
diff --git a/sourcing/view.py b/sourcing/view.py
index 5d25746..1b16e79 100644
--- a/sourcing/view.py
+++ b/sourcing/view.py
@@ -213,11 +213,14 @@ def view_item(username, hashid, raw=False):
if raw:
return Response(item.text, mimetype='text/plain')
- if 'v' in request.args and request.args['v'].isdigit():
- ItemVersion = version_class(Item)
- version = (session.query(ItemVersion)
- .filter_by(transaction_id=int(request.args['v']))
- .first())
+ v = request.args.get('v')
+ if v:
+ if not v.isdigit():
+ abort(404)
+ try:
+ version = item.versions[int(v) - 1]
+ except IndexError:
+ abort(404)
text = version.text
else:
version = None