Notification system

Asked

Viewed 216 times

1

I have the following model:

from django.db import models
from django.utils.timezone import now

# Create your models here.
class Event(models.Model):
    name = models.CharField('nombre',max_length = 255)
    place = models.CharField('lugar',max_length = 255)
    thematic = models.CharField('tema',max_length = 100)
    title_of_the_paper = models.CharField('tema abordado',max_length = 60)
    date_event  = models.DateField('realizado el', auto_now_add=False)
    author = models.ForeignKey(
        'professor.Professor', related_name='eventos', on_delete=models.CASCADE)

    class Meta:
        verbose_name = 'evento'
        verbose_name_plural = 'eventos'
        db_table = 'event'

I want to implement a notification system, which when a user inserts an event that notifies me to all other users about the created event. That Packet should use how I can change the view?

This is the view

def ajax_create_event(request):
    event_form = EventForm()
    if request.method == 'POST':
        name = request.POST['name']
        place = request.POST['place']
        thematic = request.POST['thematic']
        title_of_the_paper = request.POST['title_of_the_paper']
        date_event = request.POST['date_event']
        author = request.user.teacher_profile
        form = EventForm(request.POST, request.FILES)
        if form.is_valid():
            Event.objects.create(
                name=name, place=place, thematic=thematic,title_of_the_paper = title_of_the_paper,date_event = date_event, author=author
            )
            events = Event.objects.filter(author=author)
            data = {
                'msg': 'El evento se ha guardado satisfactoriamente',
                'page': render_to_string('event/list.html', {'events': events}, request=request),
                'header': render_to_string('event/dinamic_event.html', request=request),
                'event': request.user.teacher_profile.number_of_events
            }
        return JsonResponse(data)
    else:
        data = {
            'page': render_to_string('event/add.html', {'form': event_form}, request=request)
        }
    return JsonResponse(data)
  • Sending an email to users after doing the Event.objects.create?

1 answer

0

The Django already allows you to do this by implementing Signals which is nothing more than an implementation of design pattern Observer that allows you at certain times like before saving, while saving or deleting an object warn others who are interested in that particular event, I suggest you take a look at Signals that will solve your problem.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.