-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🗃️(teams) add Team dependencies as a tree
This provides the technical way to create Team trees. The implementation is quite naive.
- Loading branch information
Showing
8 changed files
with
174 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/backend/core/migrations/0009_team_depth_team_numchild_team_path_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Generated by Django 5.1.3 on 2024-11-26 13:55 | ||
|
||
from django.db import migrations, models | ||
|
||
from treebeard.mp_tree import MP_Node | ||
|
||
|
||
def update_team_paths(apps, schema_editor): | ||
Team = apps.get_model("core", "Team") | ||
alphabet = MP_Node.alphabet | ||
steplen = MP_Node.steplen | ||
|
||
# for default values, this resolves to: "{:04d}" | ||
path_format = f"{{:{alphabet[0]}{steplen}d}}" | ||
|
||
nodes = Team.objects.all().order_by("created_at") | ||
for i, node in enumerate(nodes, 1): | ||
node.path = path_format.format(i) | ||
|
||
if nodes: | ||
Team.objects.bulk_update(nodes, ["path"]) | ||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('core', '0008_change_user_profile_to_contact'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='team', | ||
name='depth', | ||
field=models.PositiveIntegerField(default=0), | ||
preserve_default=False, | ||
), | ||
migrations.AddField( | ||
model_name='team', | ||
name='numchild', | ||
field=models.PositiveIntegerField(default=0), | ||
), | ||
migrations.AddField( | ||
model_name='team', | ||
name='path', | ||
field=models.CharField(default='', max_length=255), | ||
preserve_default=False, | ||
), | ||
migrations.RunPython(update_team_paths, migrations.RunPython.noop), | ||
migrations.AlterField( | ||
model_name="team", | ||
name="path", | ||
field=models.CharField(max_length=255, unique=True), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters