summaryrefslogtreecommitdiff
path: root/archaeological_context_records/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'archaeological_context_records/models.py')
-rw-r--r--archaeological_context_records/models.py33
1 files changed, 22 insertions, 11 deletions
diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py
index 4a288b5dc..2654788f7 100644
--- a/archaeological_context_records/models.py
+++ b/archaeological_context_records/models.py
@@ -198,17 +198,25 @@ class ContextRecord(BaseHistorizedItem, OwnPerms, ShortMenuItem):
return self.operation.get_town_label()
@classmethod
- def get_years(cls):
- years = set()
- for res in list(cls.objects.values('operation__start_date')):
- if res['operation__start_date']:
- yr = res['operation__start_date'].year
- years.add(yr)
- return list(years)
+ def get_periods(cls, slice='year', fltr={}):
+ q = cls.objects
+ if fltr:
+ q = q.filter(**fltr)
+ if slice == 'year':
+ years = set()
+ for res in list(q.values('operation__start_date')):
+ if res['operation__start_date']:
+ yr = res['operation__start_date'].year
+ years.add(yr)
+ return list(years)
+ return []
@classmethod
- def get_by_year(cls, year):
- return cls.objects.filter(operation__start_date__year=year)
+ def get_by_year(cls, year, fltr={}):
+ q = cls.objects
+ if fltr:
+ q = q.filter(**fltr)
+ return q.filter(operation__start_date__year=year)
@classmethod
def get_operations(cls):
@@ -220,8 +228,11 @@ class ContextRecord(BaseHistorizedItem, OwnPerms, ShortMenuItem):
return cls.objects.filter(operation__pk=operation_id)
@classmethod
- def get_total_number(cls):
- return cls.objects.filter(operation__start_date__isnull=False).count()
+ def get_total_number(cls, fltr={}):
+ q = cls.objects
+ if fltr:
+ q = q.filter(**fltr)
+ return q.count()
def find_docs_q(self):
from archaeological_finds.models import FindSource