ANYONE TO HELP ME ON HOW TO CREATE AN AUTOMATIC NOTIFICATION SYSTEM THAT SENDS A MESSAGE WHENEVER AN OBJECT IS CREATED OR MODIFIED

79 views
Skip to first unread message

Byansi Samuel

unread,
Aug 22, 2023, 10:03:12 AM8/22/23
to django...@googlegroups.com

My views
from django.shortcuts import render def auto_notification(request): return render (request, "user/dashboard.html")

My models
from django.db import models from django.contrib.auth.models import User

#articles model

class Articles(models.Model):
title = models.CharField(max_length=300) date= models.DateField() author=models.ForeignKey(User, on_delete=models.CASCADE) body=models.TextField()

def __str__(self) -> str:
return self.title

#games model

GAME_TYPE=( ("action", "action"), ("adventure", "adventure"), ("racing", "racing"), ("puzzle", "puzzle"), )

MOV_TYPE=( ("action", "action"), ("adventure", "adventure"), ("sci-fi", "sci-fi"), ("horror", "horror"), ("drama", "drama"), )

GAME_OS=( ("Windows", "Windows"), ("Android", "Android"), )

class Games(models.Model): name=models.CharField(max_length=50) type=models.CharField(max_length=40, choices=GAME_TYPE) os=models.CharField(max_length=15, choices=GAME_OS) img=models.ImageField() developer=models.CharField(max_length=50) version=models.CharField(max_length=10) ratings=models.CharField(max_length=10) description=models.TextField()

def __str__(self) -> str:
return self.name class

Movies(models.Model): name=models.CharField(max_length=50) type=models.CharField(max_length=40, choices=MOV_TYPE) description=models.TextField() released=models.DateField()

def __str__(self) -> str:
return self.name

I have three models below, but l like to create a Notification System to send a message to a User whenever ;
1. An object is created in all those models
2. An object is modified in all those models

And l would like to add trick that it sends the Notification Message after 15 minutes of publiction or creation.

And I would like to pass the following data if available in the object ;
1. the Name of the Object,
2. the Image of the Object, and
3. the type of the Object.

Lastly I would like to add a :
1. Notification DELETE function, that gives User a way to delete that Message , not to appear in his or notification section again.

2. Mark as Read function, that changes the Massage Div Color

3. A notification Barge that displays the UNREAD Messages.

Am requesting anyone to help me Because Am stuck , I have no where to Start from. I will be on waiting your guidelines.

ivan harold

unread,
Aug 23, 2023, 10:22:03 AM8/23/23
to Django users

Andréas Kühne

unread,
Aug 31, 2023, 2:12:24 PM8/31/23
to django...@googlegroups.com
First of all - notification - what do you mean by notification?

If you mean that the user should be notified in the instance when someone creates / updates / deletes your models - you will need to have either server side events or websockets to communicate with the frontend. You could also poll the server (for example every 5 minutes) to check for new messages. These solutions would require that you have some javascript on the frontend.

To get this working on the backend - you would then need some sort of changes in the save method to send the notifications to the frontend. This could be as simple as creating a Notification model and then just creating a notification every time you update a model.

Regards,

Andréas


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAGQoQ3wRpg%2BcT69wqUbapHbK7KSEfwU%2BxfJ-EKRCcddY6KwtnA%40mail.gmail.com.

Michal Plsek

unread,
Sep 4, 2023, 3:20:24 AM9/4/23
to django...@googlegroups.com
Just register post_update signal with the Model you want to "watch" to be created/updated, and in optimal case send message to some asynchronous queue, which will take message 15 minutes late and processes it by creating Notification object. For example async queue = aws sqs, they even support 15min delay you want.

Dne čt 31. 8. 2023 22:11 uživatel Andréas Kühne <andrea...@hypercode.se> napsal:
Reply all
Reply to author
Forward
0 new messages