diff options
Diffstat (limited to 'archaeological_finds/models_finds.py')
-rw-r--r-- | archaeological_finds/models_finds.py | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py index 6fe56afe5..ccf42952f 100644 --- a/archaeological_finds/models_finds.py +++ b/archaeological_finds/models_finds.py @@ -1354,12 +1354,14 @@ class Find(BulkUpdatedItem, ValueGetter, BaseHistorizedItem, OwnPerms, operations_lbl.admin_order_field = \ "base_finds__context_record__operation__cached_label" - def _get_treatments(self, model, rel='upstream', limit=None): + def _get_treatments(self, model, rel='upstream', limit=None, count=False): treatments, findtreats = [], [] q = model.objects.filter( find_id=self.pk).order_by( '-treatment__year', '-treatment__index', '-treatment__start_date', '-treatment__end_date') + if count: + return q.count() for findtreat in q.distinct().all(): if findtreat.pk in findtreats: continue @@ -1371,12 +1373,6 @@ class Find(BulkUpdatedItem, ValueGetter, BaseHistorizedItem, OwnPerms, treatments.append((q.all(), findtreat.treatment)) return treatments - @property - def weight_string(self): - if not self.weight: - return "" - return "{} {}".format(self.weight, self.weight_unit or "") - def upstream_treatments(self, limit=None): from archaeological_finds.models_treatments import \ FindUpstreamTreatments @@ -1398,6 +1394,27 @@ class Find(BulkUpdatedItem, ValueGetter, BaseHistorizedItem, OwnPerms, def all_treatments(self): return self.upstream_treatments() + self.downstream_treatments() + def non_modif_treatments(self, limit=None): + from archaeological_finds.models_treatments import \ + FindNonModifTreatments + return self._get_treatments(FindNonModifTreatments, 'finds', + limit=limit) + + def non_modif_treatments_count(self): + from archaeological_finds.models_treatments import \ + FindNonModifTreatments + return self._get_treatments(FindNonModifTreatments, 'finds', + count=True) + + def limited_non_modif_treatments(self): + return self.non_modif_treatments(15) + + @property + def weight_string(self): + if not self.weight: + return "" + return "{} {}".format(self.weight, self.weight_unit or "") + def get_department(self): bf = self.get_first_base_find() if not bf: |