Skip to content

Commit

Permalink
Added model, serializer and viewset for model News Reaction
Browse files Browse the repository at this point in the history
  • Loading branch information
JarandJR committed Sep 26, 2023
1 parent 194724e commit 201c0c9
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 7 deletions.
17 changes: 17 additions & 0 deletions app/content/migrations/0054_remove_news_reactions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.0.8 on 2023-09-26 16:11

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('content', '0053_news_emojis_allowed_news_reactions'),
]

operations = [
migrations.RemoveField(
model_name='news',
name='reactions',
),
]
7 changes: 0 additions & 7 deletions app/content/models/news.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@ class News(BaseModel, OptionalImage, BasePermissionModel):
)
body = models.TextField()
emojis_allowed = models.BooleanField(default=False)
reactions = models.ForeignKey(
Reaction,
on_delete=models.SET_NULL,
blank=True,
null=True,
related_name="reactions",
)

write_access = AdminGroup.all()

Expand Down
21 changes: 21 additions & 0 deletions app/emoji/models/news_reaction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from django.db import models

from app.common.enums import Groups
from app.common.permissions import BasePermissionModel
from app.content.models.news import News
from app.emoji.models.reaction import Reaction
from app.util.models import BaseModel


class NewsReaction(BaseModel, BasePermissionModel):
reaction = models.ForeignKey(Reaction, on_delete=models.CASCADE)
news = models.ForeignKey(News, on_delete=models.CASCADE)

write_access = [Groups.TIHLDE]

class Meta:
constraints = [
models.UniqueConstraint(
fields=["reaction", "news"], name="unique together: reaction and news"
)
]
11 changes: 11 additions & 0 deletions app/emoji/serializers/news_reaction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from app.common.serializers import BaseModelSerializer
from app.emoji.models.news_reaction import NewsReaction


class UserNewsReactionSerializer(BaseModelSerializer):
class Meta:
model = NewsReaction
fields = (
"reaction",
"news",
)
Empty file.

0 comments on commit 201c0c9

Please sign in to comment.