Skip to content

querysets

django_spire.notification.app.querysets

AppNotificationQuerySet

Bases: HistoryQuerySet, NotificationContentObjectQuerySet

annotate_is_viewed_by_user

Source code in django_spire/notification/app/querysets.py
def annotate_is_viewed_by_user(self, user: User) -> QuerySet:
    return self.by_user(user=user).annotate(viewed=Case(
        When(views__user=user, then=Value(True)),
        default=Value(False),
        output_field=BooleanField()
    ))

ordered_by_priority_and_sent_datetime

Source code in django_spire/notification/app/querysets.py
def ordered_by_priority_and_sent_datetime(self):
    priority_order = Case(
        When(notification__priority=NotificationPriorityChoices.LOW, then=Value(3)),
        When(notification__priority=NotificationPriorityChoices.MEDIUM, then=Value(2)),
        When(notification__priority=NotificationPriorityChoices.HIGH, then=Value(1)),
        output_field=IntegerField(),
    )
    return self.annotate(priority_order=priority_order).order_by(
        'priority_order',
        '-notification__sent_datetime'
    )

by_user

Source code in django_spire/notification/app/querysets.py
def by_user(self, user: User) -> QuerySet:
    return self.filter(notification__user=user)

by_users

Source code in django_spire/notification/app/querysets.py
def by_users(self, users: list[User]):
    return self.filter(notification__user__in=users)

exclude_viewed_by_user

Source code in django_spire/notification/app/querysets.py
def exclude_viewed_by_user(self, user: User) -> QuerySet:
    return self.by_user(user=user).exclude(views__user=user)

is_sent

Source code in django_spire/notification/app/querysets.py
def is_sent(self) -> QuerySet:
    return self.filter(notification__status=NotificationStatusChoices.SENT)