diff options
Diffstat (limited to 'archaeological_files/models.py')
-rw-r--r-- | archaeological_files/models.py | 36 |
1 files changed, 29 insertions, 7 deletions
diff --git a/archaeological_files/models.py b/archaeological_files/models.py index 6d5390737..a1e8912f4 100644 --- a/archaeological_files/models.py +++ b/archaeological_files/models.py @@ -230,17 +230,39 @@ class File(BaseHistorizedItem, OwnPerms, ValueGetter, ShortMenuItem): return sorted(owns.all(), key=lambda x:x.cached_label) @classmethod - def get_years(cls): - return [res['year'] for res in list(cls.objects.values('year').annotate( - Count("id")).order_by())] + def get_periods(cls, slice='year', fltr={}): + q = cls.objects + if fltr: + q = q.filter(**fltr) + if slice == 'year': + return [res['year'] for res in list(q.values('year' + ).annotate(Count("id")).order_by())] + elif slice == 'month': + return [(res['creation_date'].year, res['creation_date'].month) + for res in list(q.values('creation_date' + ).annotate(Count("id")).order_by())] + return [] @classmethod - def get_by_year(cls, year): - return cls.objects.filter(year=year) + def get_by_year(cls, year, fltr={}): + q = cls.objects + if fltr: + q = q.filter(**fltr) + return q.filter(year=year) @classmethod - def get_total_number(cls): - return cls.objects.count() + def get_by_month(cls, year, month, fltr={}): + q = cls.objects + if fltr: + q = q.filter(**fltr) + return q.filter(creation_date__year=year, creation_date__month=month) + + @classmethod + def get_total_number(cls, fltr={}): + q = cls.objects + if fltr: + q = q.filter(**fltr) + return q.count() def get_values(self, prefix=''): values = super(File, self).get_values(prefix=prefix) |