Model.objects.filter(pk__in=[list of ids])
and
Model.objects.filter(pk__in=[1,2,3])
How do I show this data in a template?
def xx(request):
return HttpResponse(Model.objects.filter(pk__in=[1,2,3]))
It means, give me all objects of model Model
that either have 1
,2
or 3
as their primary key.
See Field lookups - in.
You get a list of objects back you can show them in the template like every other list, using the for
template tag:
{% for object in objects %}
Some value: {{ object.value }}
{% endfor %}
To learn how to create a Django application you should read the tutorial or the Django book.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With