From 025959b715fc1e088dde189d11ac37e431b35911 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Wed, 6 May 2020 19:39:36 +0200 Subject: Find: add a "first" material type getter --- archaeological_finds/models_finds.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'archaeological_finds/models_finds.py') diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py index 25563edd0..b0c5a0332 100644 --- a/archaeological_finds/models_finds.py +++ b/archaeological_finds/models_finds.py @@ -1684,8 +1684,17 @@ class Find(BulkUpdatedItem, ValueGetter, DocumentItem, BaseHistorizedItem, @property def materials(self): - return u" ; ".join([str(material) - for material in self.material_types.all()]) + return " ; ".join([str(material) + for material in self.material_types.all()]) + + def get_first_material_type(self): + model = self.__class__.material_types.through + q = model.objects.filter(find=self) + if not q.count(): + return + if q.filter(materialtype__parent__isnull=True).count(): + q = q.filter(materialtype__parent__isnull=True) + return q.order_by("materialtype__label")[0].materialtype @property def show_url(self): -- cgit v1.2.3