Hey everyone, l got a problem. Am trying to retrieve a single latest object added everytime, and display it in the template.
Below is my codes but;
Help me figure it out the source of the problem in these different instances below 👇
_______________________ issue number 1_______
#Action/models.py
class ActionGame(models.Model):
name=models.Charfield()
published=models.DateTimeField()
#Action/views.py
from Action.models import ActionGame
def action (request):
latest_action=ActionGame.objects.filter(published=published). latest()
Context={ 'latest_action': latest_action }
return....
But it returns *error* :
name 'published' is not defined
____________________ issue number 2________
#Action/models.py
class ActionGame(models.Model):
name=models.Charfield()
published=models.DateTimeField()
class Meta:
get_latest_by='published'
#Action/views.py
........
latest_action=ActionGame.objects. latest()
.......
#but it returns *error* :
'ActionGame' object is not iterable
Even if I try this:
............
latest_action=ActionGame.objects. latest('published')
.......
#it returns the Same error:
'ActionGame' object is not iterable
But this second issue, the error is referred in #action.html
{% for x in latest _action %}
<p>{{ x.game_name }}</p>
{% endfor %}
Please l need your assistance.
I'm Samuel,
Thanks
Hey everyone, l got a problem. Am trying to retrieve a single latest object added everytime, and display it in the template.
Below is my codes but;Help me figure it out the source of the problem in these different instances below 👇
_______________________ issue number 1_______
#Action/models.py
class ActionGame(models.Model):
name=models.Charfield()
published=models.DateTimeField()#Action/views.py
from Action.models import ActionGamedef action (request):
latest_action=ActionGame.objects.filter(published=published). latest()
Context={ 'latest_action': latest_action }
return....But it returns *error* :
name 'published' is not defined
____________________ issue number 2________
#Action/models.py
class ActionGame(models.Model):
name=models.Charfield()
published=models.DateTimeField()
class Meta:
get_latest_by='published'#Action/views.py
........
latest_action=ActionGame.objects. latest()
.......#but it returns *error* :
'ActionGame' object is not iterableEven if I try this:
............
latest_action=ActionGame.objects. latest('published')
.......#it returns the Same error:
'ActionGame' object is not iterableBut this second issue, the error is referred in #action.html
{% for x in latest _action %}
<p>{{ x.game_name }}</p>
{% endfor %}
Please l need your assistance.
I'm Samuel,
Thanks
--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAGQoQ3wMUno6hLAO-1FtN0Nn7VtkCn4qf-O4U%3DpeJ4JzY%2B%3DcAQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAK4qSCeBCST7o-5WZx%2BmhGO2yH-Msdse%3DKusk9UOyW8XZBXRBw%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAD9bWYwtxjinYmeNWZvBdCdQB5zAa3je1bwMjUhmzEjzF0Q_bg%40mail.gmail.com.
Hey thanks, but l tried to use ordering=('-published')
Se comments below.
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/CAGQoQ3wMUno6hLAO-1FtN0Nn7VtkCn4qf-O4U%3DpeJ4JzY%2B%3DcAQ%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/CAK4qSCeBCST7o-5WZx%2BmhGO2yH-Msdse%3DKusk9UOyW8XZBXRBw%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/CAD9bWYwtxjinYmeNWZvBdCdQB5zAa3je1bwMjUhmzEjzF0Q_bg%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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/A09FDF66-9845-4B93-854D-8BBFC4F5A03D%40showmethesource.org.