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
latest_action=ActionGame.objects.latest("published") - that would give you the last published item. Another way would be:
latest_action=ActionGame.objects.order_by("published").last()
____________________ 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+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.
No comments:
Post a Comment