1

So, I recently imported Django-notifications and have successfully added a notification or two. Now I want to look at the list page. In my urls I have added the notification endpoint path('notifications/', include("notifications.urls")), and when I go to the url, I get the output that matches the documentation:

Now, How do I go about changing the notification url. I tried to create an app for notifications python manage.py startapp notifications, but it said that one already existed. I feel like I'm missing something simple, but I can't put a finger on it.

Micah Pearce
  • 1,805
  • 3
  • 28
  • 61

1 Answers1

1

You can't create your own app, notifications, because you already have an installed app called notifications. This is the app you downloaded/installed and added to your_project/settings.py under INSTALLED_APPS

To view the default list, you can python manage.py runserver, and navigate to localhost:8000/notifications/' to see the defaultlist.html`.

From there, I recommend creating your own list. Looking at the documentation here, you'll find all the QuerySet methods. You can build a view based on these queries. e.g. your-app/views.py:

...

# Get all unread notifications for current user.
def unread_notifications(request):
    context = {
        'notifications': request.user.notifications.unread()
    }

    return render(request, 'your-app/unread_notifications.html', context)

And your your-app/unread_notifications.html (assuming bootstrap):

<ul class="notifications">
    {% for notice in notifications %}
    <div class="alert alert-block alert-{{ notice.level }}">
        <a class="close pull-right" href="{% url 'notifications:mark_as_read' notice.slug %}">
            <i class="icon-close"></i>
        </a>

        <h4>
            <i class="icon-mail{% if notice.unread %}-alt{% endif %}"></i>
            {{ notice.actor }}
            {{ notice.verb }}
            {% if notice.target %}
            of {{ notice.target }}
            {% endif %}
        </h4>

        <p>{{ notice.timesince }} ago</p>

        <p>{{ notice.description|linebreaksbr }}</p>

        <div class="notice-actions">
            {% for action in notice.data.actions %}
            <a class="btn" href="{{ action.href }}">{{ action.title }}</a>
            {% endfor %}
        </div>
    </div>
    {% endfor %}
</ul>