diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2021-02-02 19:40:03 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2021-02-28 12:15:24 +0100 |
commit | f6ecf5a0ff7b58614301200ec23fcc51d0126db6 (patch) | |
tree | 3dccda97275a6e5bbbc8330a722716bc55bfae1f /archaeological_finds | |
parent | 1c7c4dad21ce0c178a04bb2a5c2097df1c95ea5c (diff) | |
download | Ishtar-f6ecf5a0ff7b58614301200ec23fcc51d0126db6.tar.bz2 Ishtar-f6ecf5a0ff7b58614301200ec23fcc51d0126db6.zip |
Treatments: manage filter treatment type with hierarchy (do not hide because parent is not OK)
Diffstat (limited to 'archaeological_finds')
-rw-r--r-- | archaeological_finds/models_finds.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py index 8ee742b43..a1321d678 100644 --- a/archaeological_finds/models_finds.py +++ b/archaeological_finds/models_finds.py @@ -131,6 +131,32 @@ class TreatmentType(HierarchicalType): verbose_name_plural = _("Treatment types") ordering = ('order', 'label',) + @classmethod + def get_types(cls, dct=None, instances=False, exclude=None, + empty_first=True, default=None, initial=None, force=False, + full_hierarchy=False): + types = super(TreatmentType, cls).get_types( + dct=dct, instances=instances, exclude=exclude, + empty_first=empty_first, default=default, initial=initial, + force=force, full_hierarchy=full_hierarchy) + if dct and not exclude: + rank = 0 + if instances: + type_list = [ty.pk for ty in types] + if types: + rank = types[-1].rank + else: + type_list = [idx for idx, __ in types] + q = cls.objects.filter(**dct).exclude(pk__in=type_list) + for t in q.all(): + if instances: + rank += 1 + t.rank = rank + types.append(t) + else: + types.append((t.pk, str(t))) + return types + post_save.connect(post_save_cache, sender=TreatmentType) post_delete.connect(post_save_cache, sender=TreatmentType) |