Skip to content

Commit

Permalink
feat(taxref): taxons comparison through path
Browse files Browse the repository at this point in the history
  • Loading branch information
bouttier committed Oct 8, 2024
1 parent a110d24 commit 92bf84f
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions apptax/taxonomie/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from typing import Self
from flask import url_for
from sqlalchemy import ForeignKey, select, func, event

Expand Down Expand Up @@ -230,6 +231,9 @@ def where_params(cls, filters=None, *, query):
query = query.filter(col.ilike(value + "%"))
return query

def __le__(self, other: Self) -> bool:
return self.tree <= other.tree


@serializable
class BibListes(db.Model):
Expand Down Expand Up @@ -546,6 +550,11 @@ class TaxrefTree(db.Model):
taxref = db.relationship(Taxref, backref=backref("tree", uselist=False))
path = db.Column(db.String, nullable=False)

def __le__(self, other: Self) -> bool:
# self <= other means taxon other is the same or a parent of self
p1, p2 = self.path.split("."), other.path.split(".")
return len(p1) >= len(p2) and p1[: len(p2)] == p2


# Taxref deffered properties

Expand Down

0 comments on commit 92bf84f

Please sign in to comment.