[Answer]-Display data from models in website

1👍

You need to iterate over the queryset:

<ul>
    {% for service in latest_services %}
        <li>{{ service.service_name }}</li>
    {% endfor %}
</ul>

Anyway, if you want to display the latest entries, you should add a new field to your model with the date. For example:

class Service(models.Model):
    created_on = models.DateTimeField(auto_now=True)
    service_name = models.CharField(max_length=200)
    service_code = models.IntegerField(default=0, unique=True)

And then in your query:

latest_services = Service.objects.order_by('created_on')
👤cor

Leave a comment