Skip to content

Commit

Permalink
Support metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
hugobessa committed Dec 20, 2024
1 parent 9bd67ad commit 68689e8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions vintasend_django/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,6 @@ class Migration(migrations.Migration):
verbose_name="modified",
),
),
(
"meta",
models.JSONField(blank=True, default=dict, verbose_name="meta"),
),
(
"context_used",
models.JSONField(
Expand All @@ -97,6 +93,13 @@ class Migration(migrations.Migration):
to=settings.AUTH_USER_MODEL,
),
),
(
"metadata",
models.JSONField(
null=True,
verbose_name="Metadata for the notification adapter",
),
),
],
options={
"ordering": ("-created",),
Expand Down
5 changes: 2 additions & 3 deletions vintasend_django/models.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from django.contrib.auth import get_user_model
from django.db import models
from django.utils.translation import gettext_lazy as _

from model_utils.fields import AutoCreatedField, AutoLastModifiedField

from vintasend_django.constants import NotificationStatusChoices, NotificationTypesChoices

from django.contrib.auth import get_user_model


User = get_user_model()

Expand All @@ -30,7 +29,7 @@ class Notification(models.Model):
created = AutoCreatedField(_("created"), db_index=True)
modified = AutoLastModifiedField(_("modified"), db_index=True)

meta = models.JSONField(_("meta"), default=dict, blank=True)
metadata = models.JSONField(_("metadata"), default=dict, blank=True)

context_used = models.JSONField(_("context used when notification was sent"), null=True)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import uuid
from collections.abc import Iterable

from django.db.models import Q
from django.db.models import Q, QuerySet

from vintasend.constants import NotificationStatus, NotificationTypes
from vintasend.exceptions import (
Expand All @@ -16,8 +16,8 @@
UpdateNotificationKwargs,
)
from vintasend.services.notification_backends.base import BaseNotificationBackend

from vintasend_django.models import Notification as NotificationModel
from django.db.models import QuerySet


class DjangoDbNotificationBackend(BaseNotificationBackend):
Expand Down Expand Up @@ -72,6 +72,7 @@ def persist_notification(
send_after: datetime.datetime | None,
subject_template: str | None = None,
preheader_template: str | None = None,
metadata: dict | None = None,
) -> Notification:
notification_instance = NotificationModel.objects.create(
user_id=str(user_id),
Expand Down

0 comments on commit 68689e8

Please sign in to comment.