Skip to content

Commit

Permalink
add FK on Forum
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentporte committed Aug 29, 2024
1 parent 306fe2a commit f0010d1
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lacommunaute/forum/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class ForumAdmin(BaseForumAdmin):
fieldsets = BaseForumAdmin.fieldsets
fieldsets[0][1]["fields"] += ("short_description", "certified", "tags")
fieldsets[0][1]["fields"] += ("short_description", "certified", "tags", "partner")
fieldsets[1][1]["fields"] += (
"members_group",
"invitation_token",
Expand Down
8 changes: 8 additions & 0 deletions lacommunaute/forum/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ def with_tags(self, create, extracted, **kwargs):
for tag in extracted:
self.tags.add(tag)

@factory.post_generation
def with_partner(self, create, extracted, **kwargs):
if not create or not extracted:
return

self.partner = extracted
self.save()


class CategoryForumFactory(ForumFactory):
type = Forum.FORUM_CAT
Expand Down
21 changes: 21 additions & 0 deletions lacommunaute/forum/migrations/0018_forum_partner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 5.0.8 on 2024-08-29 14:34

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("forum", "0017_forum_tags"),
("partner", "0001_initial"),
]

operations = [
migrations.AddField(
model_name="forum",
name="partner",
field=models.ForeignKey(
blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to="partner.partner"
),
),
]
2 changes: 2 additions & 0 deletions lacommunaute/forum/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from lacommunaute.forum.enums import Kind as Forum_Kind
from lacommunaute.forum_conversation.models import Topic
from lacommunaute.forum_upvote.models import UpVote
from lacommunaute.partner.models import Partner
from lacommunaute.utils.validators import validate_image_size


Expand Down Expand Up @@ -42,6 +43,7 @@ class Forum(AbstractForum):
upvotes = GenericRelation(UpVote, related_query_name="forum")

tags = TaggableManager()
partner = models.ForeignKey(Partner, on_delete=models.CASCADE, null=True, blank=True)

objects = ForumQuerySet().as_manager()

Expand Down

0 comments on commit f0010d1

Please sign in to comment.