Added a viewed count to the models

This commit is contained in:
2014-03-03 12:22:07 +10:00
parent 5657a9cb38
commit 9fef71c877
2 changed files with 6 additions and 0 deletions

2
.gitignore vendored
View File

@@ -2,3 +2,5 @@
.DS_Store .DS_Store
.spyderproject .spyderproject
reports/ reports/
.idea/workspace.xml
.idea/rockviewer.iml

View File

@@ -58,6 +58,7 @@ class Sample(CommonInfo):
parent = models.ForeignKey(Category, blank=True, null=True, parent = models.ForeignKey(Category, blank=True, null=True,
on_delete=models.SET_NULL, on_delete=models.SET_NULL,
related_name="samples") related_name="samples")
viewed_count = models.IntegerField(default=0)
#Use the inheritance manager for handling subclasses #Use the inheritance manager for handling subclasses
objects = InheritanceManager() objects = InheritanceManager()
@@ -72,6 +73,8 @@ class Sample(CommonInfo):
def url(self): def url(self):
cat = self.GetTopParent(self.parent) cat = self.GetTopParent(self.parent)
self.viewed_count += 1
if cat.name == 'Fossils': if cat.name == 'Fossils':
return 'three_d_viewer:fossil_detail' return 'three_d_viewer:fossil_detail'
elif cat.name == 'Rocks': elif cat.name == 'Rocks':
@@ -98,6 +101,7 @@ class Mineral(Sample):
@property @property
def url(self): def url(self):
self.viewed_count += 1
return 'three_d_viewer:mineral_detail' return 'three_d_viewer:mineral_detail'