0

I'm trying to add notification feature just like social network sites do something like: ( 'x user has add comment', ' x user has like your post' ..) and so on

I was searching for a guideline for this feature in django to follow up, I found this answer "How to use django-notification to inform a user when somebody comments on their post " but since it's 6 years ago, some functions is deprecated and webpages links is down. And I believe since 6 years django community add some built-in feature make these things easier. the framework django-notification now become pinax-notifications and as I read it's based on email notification - that not what i'm looking for-.

For example let's say my current project has 3 classes in models as following :

class user(models.mode):
.....

class post(models.mode):
user = foreignkey(user)
.....

class comment(models.mode):
user = foreignkey(user)
post = foreignkey(post)
.....

class likse(models.mode):
user = foreignkey(user)
post = foreignkey(post)
comment = foreignkey(comment)
.....

Is there any guideline for modifying the project to add-on notification feature ? btw, i'm working on django 1.11 and python 3

sam
  • 63
  • 6

1 Answers1

0

In Views, use:-

from django.contrib import messages

Inside A function,add

errormessage="type error message here"
messages.error(request,errormessage ,extra_tags='alert alert-danger')

extra_tags is to give class in the template

In template

  {% if messages %}
          <ul class="messages">
          {% for message in messages %}
          <li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li>
          {% endfor %}
          </ul>
  {% endif %}

For reference go to https://docs.djangoproject.com/en/1.11/ref/contrib/messages/