[Answered ]-How to get data from Database with a range?

1👍

Have you seen the range filter?

Basically you could do:

import datetime
# ...

context_data['newNotifications'] = Notification.objects.filter(
    emailStudent=request.user).filter(
        time__range=(
            request.user.viewedNotifications,
            datetime.datetime.now()
        )
    ).count()

So your .filter() argument would be time__range=(start_date,end_date) where start_date comes from your request and end_date is datetime.datetime.now().

Leave a comment