Шаблон уведомления печатает только элементы после 3-й позиции

Шаблон уведомлений выводит элементы только после 3-й позиции. Когда я проверяю элемент, чтобы проверить, отображается ли он во фронтенде, он там есть, но это просто пустой html тег <p>. За исключением этой незначительной ошибки, все работает нормально. Не знаю, как действовать дальше, любая помощь будет очень признательна.

Вот мои models.py

class Notification(models.Model):
    MESSAGE = 'message'
    APPLICATION = 'application'

    CHOICES = (
        (MESSAGE, 'Message'),
        (APPLICATION, 'Application')
    )

    to_user = models.ForeignKey(User, related_name='notifications', on_delete=models.CASCADE)
    notification_type = models.CharField(max_length=20, choices=CHOICES)
    is_read = models.BooleanField(default=False)
    extra_id = models.IntegerField(null=True, blank=True)

    created_at = models.DateTimeField(auto_now_add=True)
    created_by = models.ForeignKey(User, related_name='creatednotifications', on_delete=models.CASCADE)

    class Meta:
        ordering = ['-created_at']

notification views.py

@login_required
def notifications(request):
    goto = request.GET.get('goto', '')
    notification_id = request.GET.get('notification', 0)
    extra_id = request.GET.get('extra_id', 0)

    if goto != '':
        notification = Notification.objects.get(pk=notification_id)
        notification.is_read = True
        notification.save()

        if notification.notification_type == Notification.MESSAGE:
            return redirect('room', pk=notification.extra_id)
        elif notification.notification_type == Notification.APPLICATION:
            return redirect('room', pk=notification.extra_id)
    
    return render(request, 'notification/notifications.html')

шаблон notifications.html

{% extends 'main.html' %}

{% block content %}
    <div class="container">
        <h1 class="title">Notifications</h1>
        

        {% if not notifications %}
            No notifications yet!
        {% endif %}

        {% for notification in notifications %}
            <div class="notification">
                <p>
                    {% if notification.notification_type == 'message' %}
                        <a href="{% url 'notifications' %}?goto=room&notification={{ notification.id }}&extra_id={{ notification.extra_id }}">
                            <strong>{{ notification.created_by.username }}</strong> sent you a message<br>
                            <small>{{ notification.created_at|timesince }} ago</small>
                        </a>
                    {% elif notification.notification_type == 'application' %}
                        <a href="{% url 'notifications' %}?goto=room&notification={{ notification.id }}&extra_id={{ notification.extra_id }}">
                            <strong>{{ notification.created_by.username }}</strong> created a room<br>
                            <small>{{ notification.created_at|timesince }} ago</small>
                        </a>
                    {% endif %}
                </p>
            </div>
        {% endfor %}
    </div>
{% endblock %}

enter image description here

Уведомления, которые выводят только пустой <P>, вероятно, не имеют тип уведомления, равный 'message' или 'application'.

Вернуться на верх