Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does pk__in mean in Django?

Tags:

python

django

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]))
like image 255
zjm1126 Avatar asked Feb 04 '10 09:02

zjm1126


Video Answer


1 Answers

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.

like image 166
Felix Kling Avatar answered Oct 02 '22 21:10

Felix Kling