Reputation: 83
Say I have a list of values
list =['value1', 'value2', 'value3', ...]
Is there a way I can run a query against a whole Db and delete any entries that don't match?
The opposite of the below almost:
models.objects.filter(value__in=list).delete()
Upvotes: 2
Views: 646
Reputation: 477318
You can work with .exclude(…)
[Django-doc], so:
Model.objects.exclude(value__in=list).delete()
Upvotes: 2