-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
apps/projects: add topics as m2m relation
- Loading branch information
Showing
12 changed files
with
161 additions
and
17 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
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
33 changes: 33 additions & 0 deletions
33
adhocracy4/projects/migrations/0042_topic_alter_project_topics_project_m2mtopics.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,33 @@ | ||
# Generated by Django 4.2 on 2023-11-29 13:18 | ||
|
||
import adhocracy4.projects.fields | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("a4projects", "0041_ckeditor5_iframes"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="Topic", | ||
fields=[ | ||
( | ||
"id", | ||
models.AutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("code", models.CharField(blank=True, max_length=10, unique=True)), | ||
], | ||
), | ||
migrations.AddField( | ||
model_name="project", | ||
name="m2mtopics", | ||
field=models.ManyToManyField(to="a4projects.topic"), | ||
), | ||
] |
40 changes: 40 additions & 0 deletions
40
adhocracy4/projects/migrations/0043_migrate_topics_to_m2m_topics.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,40 @@ | ||
# Generated by Django 4.2 on 2023-11-29 13:20 | ||
import sys | ||
import importlib | ||
|
||
from django.db import migrations | ||
from django.conf import settings | ||
|
||
|
||
def add_topics_to_m2m_table(apps, schema_editor): | ||
if hasattr(settings, "A4_PROJECT_TOPICS"): | ||
project = apps.get_model("a4projects", "Project") | ||
topic = apps.get_model("a4projects", "Topic") | ||
for project in project.objects.all(): | ||
for topic_code in project.topics: | ||
proj_topic, _ = topic.objects.get_or_create( | ||
code=topic_code, | ||
) | ||
project.m2mtopics.add(proj_topic) | ||
else: | ||
pass | ||
|
||
|
||
def reverse_func(apps, schema_editor): | ||
if hasattr(settings, "A4_PROJECT_TOPICS"): | ||
project = apps.get_model("a4projects", "Project") | ||
for project in project.objects.all(): | ||
for topic in project.m2mtopics.all(): | ||
project.m2mtopics.remove(topic) | ||
else: | ||
pass | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("a4projects", "0042_topic_alter_project_topics_project_m2mtopics"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(add_topics_to_m2m_table, reverse_func), | ||
] |
16 changes: 16 additions & 0 deletions
16
adhocracy4/projects/migrations/0044_remove_project_field_topics.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,16 @@ | ||
# Generated by Django 4.2 on 2023-11-29 15:03 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("a4projects", "0043_migrate_topics_to_m2m_topics"), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name="project", | ||
name="topics", | ||
), | ||
] |
15 changes: 15 additions & 0 deletions
15
adhocracy4/projects/migrations/0045_rename_field_m2mtopics_to_topics.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,15 @@ | ||
# Generated by Django 4.2 on 2023-11-29 15:14 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("a4projects", "0044_remove_project_field_topics"), | ||
] | ||
|
||
operations = [ | ||
migrations.RenameField( | ||
model_name="project", old_name="m2mtopics", new_name="topics" | ||
), | ||
] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Changed | ||
|
||
- apps/projects: | ||
add topics model/table | ||
make topics a m2m relation to projects | ||
stop making use of django-multiselectfield as it's not maintained |
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,3 @@ | ||
### Changed | ||
|
||
- apps/projects: topics should be first created and then added to project in migration |
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,3 @@ | ||
### Fixed | ||
|
||
- apps/projects: project's topics_name property should iterate through m2m relation |
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,22 @@ | ||
# fmt: off | ||
|
||
from django.db import models | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
|
||
class TopicEnum(models.TextChoices): | ||
"""Choices for project topics.""" | ||
|
||
ANT = "ANT", _("Anti-discrimination"), | ||
WOR = "WOR", _("Work & economy"), | ||
BUI = "BUI", _("Building & living"), | ||
EDU = "EDU", _("Education & research"), | ||
CHI = "CHI", _("Children, youth & family"), | ||
FIN = "FIN", _("Finances"), | ||
HEA = "HEA", _("Health & sports"), | ||
INT = "INT", _("Integration"), | ||
CUL = "CUL", _("Culture & leisure"), | ||
NEI = "NEI", _("Neighborhood & participation"), | ||
URB = "URB", _("Urban development"), | ||
ENV = "ENV", _("Environment & public green space"), | ||
TRA = "TRA", _("Traffic") |
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