Reputation: 1579
I am building a django project and I have a list of ids [23,44,12,67] and I have a model named testmodel
tests = testmodel.objects.all()
But I want to remove/filter(I don't want to remove from database, just filter) the objects which has the ids in my list. Any help how I can achieve this in a simple way using django ?
Upvotes: 1
Views: 77
Reputation: 846
try this:
test = testmodel.objects.exclude(pk__in=[23,44,12,67])
You can find more information here
Upvotes: 2
Reputation: 10256
You need the .exclude()
ORM method:
testmodel.objects.exclude(id__in=[23,44,12,67])
Upvotes: 2