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
--
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 [email protected].
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.