From cb8f9ed670e25cef2f50557a8afc4a7abefdb410 Mon Sep 17 00:00:00 2001 From: vincent porte Date: Wed, 7 Aug 2024 16:24:19 +0200 Subject: [PATCH] feat(forum): add tags to model --- lacommunaute/forum/admin.py | 2 +- .../forum/migrations/0017_forum_tags.py | 24 +++++++++++++++++++ lacommunaute/forum/models.py | 3 +++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 lacommunaute/forum/migrations/0017_forum_tags.py diff --git a/lacommunaute/forum/admin.py b/lacommunaute/forum/admin.py index 43b934f3..520b79f3 100644 --- a/lacommunaute/forum/admin.py +++ b/lacommunaute/forum/admin.py @@ -6,7 +6,7 @@ class ForumAdmin(BaseForumAdmin): fieldsets = BaseForumAdmin.fieldsets - fieldsets[0][1]["fields"] += ("short_description", "certified") + fieldsets[0][1]["fields"] += ("short_description", "certified", "tags") fieldsets[1][1]["fields"] += ( "members_group", "invitation_token", diff --git a/lacommunaute/forum/migrations/0017_forum_tags.py b/lacommunaute/forum/migrations/0017_forum_tags.py new file mode 100644 index 00000000..51b2179e --- /dev/null +++ b/lacommunaute/forum/migrations/0017_forum_tags.py @@ -0,0 +1,24 @@ +# Generated by Django 5.0.7 on 2024-08-07 14:21 + +import taggit.managers +from django.db import migrations + + +class Migration(migrations.Migration): + dependencies = [ + ("forum", "0016_forum_certified"), + ("taggit", "0006_rename_taggeditem_content_type_object_id_taggit_tagg_content_8fc721_idx"), + ] + + operations = [ + migrations.AddField( + model_name="forum", + name="tags", + field=taggit.managers.TaggableManager( + help_text="A comma-separated list of tags.", + through="taggit.TaggedItem", + to="taggit.Tag", + verbose_name="Tags", + ), + ), + ] diff --git a/lacommunaute/forum/models.py b/lacommunaute/forum/models.py index bd07c99f..fdf68e52 100644 --- a/lacommunaute/forum/models.py +++ b/lacommunaute/forum/models.py @@ -9,6 +9,7 @@ from machina.apps.forum.abstract_models import AbstractForum from machina.models import DatedModel from storages.backends.s3boto3 import S3Boto3Storage +from taggit.managers import TaggableManager from lacommunaute.forum.enums import Kind as Forum_Kind from lacommunaute.forum_conversation.models import Topic @@ -40,6 +41,8 @@ class Forum(AbstractForum): upvotes = GenericRelation(UpVote, related_query_name="forum") + tags = TaggableManager() + objects = ForumQuerySet().as_manager() def get_absolute_url(self):