SystemNotifications handling in Django REST

Published On: 17 December 2020.By .
  • General

To manage notifications we define types of notifications in a constant files(in a dictionary) and create two tables in our database, first is NotificationObjects and second, Notifications like:

 

In NotificationObjects table we define entity_type_id which keeps the type of notification we defined in constant file (e.g. {“file_upload_notification”: 1,…}) and a entity_id which keeps id of related thing; like for file_upload type of notification we keep file id in entity_id to fetch details of of file from file table through its id. Next in actor field we put id of user who is creating the notification.

In next table i.e. Notifications we put foreign key which references notificationobject, notifier which is the user to whom notification to be sent, is_read to mark if notification is read by the notified user.

Next we create two functions to create notificationObject and notification.

Next we need to call first one to create the notification for appropriate type like:

Next we fetch all the users(or members to whom notifications be sent) and and notifications for each of them like:

 

Related content

That’s all for this blog