Notifications API Reference
notifications.models
Models for the notifications application.
Defines the structure for systemic and event-driven notifications sent to users (e.g., budget alerts, goal achievements).
Notification
Bases: Model
Represents a single message or alert sent to a user.
Attributes:
| Name | Type | Description |
|---|---|---|
user |
ForeignKey
|
The recipient of the notification. |
type |
CharField
|
Classification (Budget Alert, System, etc.). |
title |
CharField
|
Short descriptive heading. |
message |
TextField
|
The full body content. |
is_read |
BooleanField
|
Tracks if the user has seen the alert. |
created_at |
DateTimeField
|
When the alert was generated. |
Source code in notifications/models.py
Meta
notifications.serializers
Serializers for the notifications application.
Handles the conversion of notification instances into JSON data.
NotificationSerializer
Bases: ModelSerializer
Serializer for the Notification model.
Exposes core fields including read status and creation timestamp.
Source code in notifications/serializers.py
notifications.views
Views for handling user notifications and read status.
Provides endpoints to list notifications, mark them as read individually, or mark all as read simultaneously.
NotificationViewSet
Bases: ModelViewSet
ViewSet for managing user notifications.
Supports listing, creation (systemic), and state changes (marking as read).
Source code in notifications/views.py
get_queryset()
Return notifications filtered by the currently authenticated user.
Returns:
| Name | Type | Description |
|---|---|---|
QuerySet |
Authenticated user's notifications. |
mark_all_read(request)
Mark every notification for the user as read.
Returns:
| Name | Type | Description |
|---|---|---|
Response |
Success confirmation message. |
Source code in notifications/views.py
mark_read(request, pk=None)
Mark a single notification as read by its primary key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pk
|
int
|
Primary key of the notification. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Response |
Success confirmation message. |
Source code in notifications/views.py
perform_create(serializer)
Automatically link the authenticated user to newly created notifications.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
serializer
|
NotificationSerializer
|
The validated notification serializer. |
required |