Skip to content

Commit

Permalink
create model class for reactions
Browse files Browse the repository at this point in the history
  • Loading branch information
smanga24 committed Jan 15, 2025
1 parent 9349325 commit 7d51d0b
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
73 changes: 73 additions & 0 deletions src/interactions/migrations/0004_reaction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Generated by Django 5.1.5 on 2025-01-15 14:07

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


class Migration(migrations.Migration):

dependencies = [
("interactions", "0003_alter_bookmark_page_alter_recentpageview_page"),
("wagtailcore", "0094_alter_page_locale"),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name="Reaction",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("created_at", models.DateTimeField(auto_now_add=True)),
("updated_at", models.DateTimeField(auto_now=True)),
(
"type",
models.CharField(
choices=[
("celebrate", "Celebrate"),
("like", "Like"),
("love", "Love"),
("dislike", "Dislike"),
("unhappy", "Unhappy"),
],
help_text="Select the type of reaction (e.g., Like or Dislike).",
max_length=10,
verbose_name="Reaction Type",
),
),
(
"page",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="%(app_label)s_%(class)ss",
to="wagtailcore.page",
),
),
(
"user",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="+",
to=settings.AUTH_USER_MODEL,
),
),
],
options={
"ordering": ["-updated_at"],
"abstract": False,
"constraints": [
models.UniqueConstraint(
fields=("user", "page"), name="unique_interactions_reaction"
)
],
},
),
]
17 changes: 17 additions & 0 deletions src/interactions/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,20 @@ class Bookmark(UserPage):

class RecentPageView(UserPage):
count = models.PositiveIntegerField(default=1)


class ReactionType(models.TextChoices):
CELEBRATE = "celebrate", "Celebrate"
LIKE = "like", "Like"
LOVE = "love", "Love"
DISLIKE = "dislike", "Dislike"
UNHAPPY = "unhappy", "Unhappy"


class Reaction(UserPage):
type = models.CharField(
max_length=10,
choices=ReactionType.choices,
verbose_name="Reaction Type",
help_text="Select the type of reaction (e.g., Like or Dislike).",
)

0 comments on commit 7d51d0b

Please sign in to comment.