Thank you So much for helping me out!!
Thanks a lot
Meera Gangani
On Fri, May 29, 2020 at 5:08 PM Sencer Hamarat <sencerhamarat@gmail.com> wrote:
Hi Meera,You have only one record because of you are using .latest() method in the query.If you want to last 3 or 4 object ordered by descending date, you should write queryset like this:notifications = Notification.objects.all().order_by('-date')[0:x] # The 'x' could be 3 or 4 by your choice.An pass the notifications to request context in 'render_to_response' call. {'notifications': notifications}The you have to iterate notifications in template via for loop. For example;{% for notification in notifications %}<div>notification.title</div><div>notification.message</div><div>notification.date</div>{% endfor %}Saygılarımla,Sencer HAMARAT--On Fri, May 29, 2020 at 1:59 PM meera gangani <meeragangani12@gmail.com> wrote:i want to fetch last 3 records for notification!!--But I only fetch last 1 record.Can you please help me out!!!Can i use filters??And my model fields are:title=message=date=And i want to fetch last 3-4 records
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CANaPPPJVprm5gE0FNFWqPDGdW_ciq15JQXLmjVHinJkHPwRdqQ%40mail.gmail.com.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CACp8TZh3iD4M2%3Ddq4NOrPTpOzAYCFxx_kduS6%2BK%2BEG2kPDFkYA%40mail.gmail.com.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CANaPPP%2BwXHHeQfZOrqAOfwPfLwKhGUiV4v4Nbu%3DnRYNeWS-qrQ%40mail.gmail.com.
No comments:
Post a Comment