|
8 | 8 | from django.urls import reverse |
9 | 9 | from django.utils import timezone |
10 | 10 | from django.utils.functional import cached_property |
| 11 | +from django.utils.module_loading import import_string |
11 | 12 | from django.utils.translation import gettext_lazy as _ |
12 | 13 | from django_ckeditor_5.fields import CKEditor5Field |
13 | 14 | from django_enumfield.enum import EnumField |
|
19 | 20 | from adhocracy4.models import base |
20 | 21 |
|
21 | 22 | from .enums import Access |
22 | | -from .fields import TopicField |
23 | 23 | from .utils import get_module_clusters |
24 | 24 | from .utils import get_module_clusters_dict |
25 | 25 |
|
26 | 26 |
|
| 27 | +class Topic(models.Model): |
| 28 | + code = models.CharField(blank=True, max_length=10, unique=True) |
| 29 | + |
| 30 | + def __str__(self): |
| 31 | + if hasattr(settings, "A4_PROJECT_TOPICS"): |
| 32 | + topics_enum = import_string(settings.A4_PROJECT_TOPICS) |
| 33 | + return str(topics_enum(self.code).label) |
| 34 | + return self.code |
| 35 | + |
| 36 | + |
27 | 37 | class ProjectManager(models.Manager): |
28 | 38 | def get_by_natural_key(self, name): |
29 | 39 | return self.get(name=name) |
@@ -259,9 +269,8 @@ class Project( |
259 | 269 | "dashboard." |
260 | 270 | ), |
261 | 271 | ) |
262 | | - topics = TopicField( |
263 | | - verbose_name=_("Project topics"), help_text=_("Add topics to your project.") |
264 | | - ) |
| 272 | + topics = models.ManyToManyField(Topic) |
| 273 | + |
265 | 274 | project_type = models.CharField( |
266 | 275 | blank=True, max_length=256, default="a4projects.Project" |
267 | 276 | ) |
@@ -321,8 +330,7 @@ def has_moderator(self, user): |
321 | 330 | @cached_property |
322 | 331 | def topic_names(self): |
323 | 332 | if hasattr(settings, "A4_PROJECT_TOPICS"): |
324 | | - choices = dict(settings.A4_PROJECT_TOPICS) |
325 | | - return [choices[topic] for topic in self.topics] |
| 333 | + return [topic.name for topic in self.topics.all()] |
326 | 334 | return [] |
327 | 335 |
|
328 | 336 | @cached_property |
|
0 commit comments