1+ from django .db import models
2+ from tree_queries .models import TreeNode
3+
4+ # Fetch nodes in depth-first search order: .objects.with_tree_fields()
5+ # All nodes will have the tree_path, tree_ordering and tree_depth attributes.
6+ # Fetch any node: .objects.order_by("?").first()
7+ # Fetch all ancestors starting from the root: .ancestors(include_self=True)
8+ # Fetch direct children: .children.with_tree_fields()
9+ # Fetch all descendants in depth-first search order, including self: .descendants(include_self=True)
10+ # Temporarily override the ordering by siblings: Node.objects.order_siblings_by("id")
11+ # Breadth-first search: .objects.with_tree_fields().extra(order_by=["__tree.tree_depth", "__tree.tree_ordering"])
12+ # Filter by depth: .objects.with_tree_fields().extra(where=["__tree.tree_depth <= %s"], params=[1])
13+ class Attribute (TreeNode ):
14+ name = models .CharField (max_length = 255 )
15+ project = models .ForeignKey ('project.Project' , on_delete = models .DO_NOTHING )
16+ level = models .ForeignKey ('attribute.Level' , on_delete = models .DO_NOTHING )
17+
18+ class Meta : db_table = 'attribute'
19+
20+ def __str__ (self ): return self .name
21+
22+
23+ class Level (TreeNode ):
24+ uid = models .BigIntegerField ()
25+ name = models .CharField (max_length = 255 )
26+ project = models .ForeignKey ('project.Project' , on_delete = models .DO_NOTHING )
27+
28+ class Meta : db_table = 'level'
29+
30+ def __str__ (self ): return self .name
0 commit comments