Relationship with tree_id

33 views
Skip to first unread message

João Pedro

unread,
Nov 2, 2020, 5:49:58 AM11/2/20
to django-mptt-dev
Hello everyone!

Is it possible to create a relationship  connecting to the tree_id?

For instance I have simple MPTTModel and another ProductCode (standard) model. I would like to relate a code to a tree_id, so all the nodes on the same tree have the same ProductCode as reference.

code | Tree_id
FLX   | 1 

Tree_id | Name | Node_id | Parent 
1            | A         | 1             | NULL
1            | B         | 2             | 1
2            | C         | 3             | NULL


Query the database  for code "FLX" would return nodes A and B. Do you guys think it's possible?

Thanks in advance   

Matthias Kestenholz

unread,
Nov 2, 2020, 6:07:30 AM11/2/20
to django-...@googlegroups.com
Hi João

I wouldn't rely on the tree_id value. Moving root nodes or even inserting new root nodes (with order_insertion_by certainly) will assign new tree_id values to nodes.

You're probably better off adding the relation yourself; maybe only to root nodes to avoid redundancies and possibly conflicting values within trees.

Matthias



--
You received this message because you are subscribed to the Google Groups "django-mptt-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-mptt-d...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-mptt-dev/6e17a2a8-1e1e-4f65-ac68-d7e67abf9001n%40googlegroups.com.


--
Feinheit AG - Matthias Kestenholz - Direkt +41 79 444 78 96 - Zentrale +41 555 11 11 41

João Pedro

unread,
Nov 2, 2020, 8:09:08 AM11/2/20
to django-mptt-dev
In this case, there is no quick way to make children inherit the parent node configuration? This means if I have the root set as FLX, all children that were null get set to FLX, if a set a node in the subtree, this subtree get converted, etc.


Setting root to FLX:

Tree_id | Name | Node_id | Parent | Code
1            | A         | 1             | NULL   |  FLX
1            | B         | 2             | 1           |  FLX   
1            | C         | 3             | 1           |  FLX   
1            | D         | 4             | 2            |  FLX   
1            | E         | 5             | 3            |  FLX   

Setting B to RIG:

Tree_id | Name | Node_id | Parent | Code
1            | A         | 1             | NULL   |  FLX
1            | B         | 2             | 1           |  RIG
1            | C         | 3             | 1           |  FLX   
1            | D         | 4             | 2            |  RIG
1            | E         | 5             | 3            |  FLX   


Cheers!
Reply all
Reply to author
Forward
0 new messages