mirror of
https://github.com/PokeAPI/pokeapi
synced 2024-11-26 13:20:26 +00:00
36 lines
679 B
Python
Executable file
36 lines
679 B
Python
Executable file
from django.db import models
|
|
|
|
from datetime import date, timedelta
|
|
|
|
|
|
class ViewManager(models.Manager):
|
|
|
|
def increment_view_count(self):
|
|
|
|
view, _ = ResourceView.objects.get_or_create(
|
|
date=date.today()
|
|
)
|
|
|
|
view.count = view.count + 1
|
|
|
|
view.save()
|
|
|
|
def total_count(self):
|
|
|
|
t = 0
|
|
for v in ResourceView.objects.all():
|
|
t += v.count
|
|
|
|
return t
|
|
|
|
|
|
class ResourceView(models.Model):
|
|
|
|
objects = ViewManager()
|
|
|
|
def __unicode__(self):
|
|
return str(self.date) + ' - ' + str(self.count)
|
|
|
|
count = models.IntegerField(max_length=1000, default=0)
|
|
|
|
date = models.DateField(auto_now=True)
|