[Fixed]-Django get objects for many IDs

28👍

There’s an __in (documentation here) field lookup that you can use to get all objects for which a certain field matches one of a list of values

objects = SomeModel.objects.filter(id__in=id_set)

Works just the same for lots of different field types (e.g. CharFields), not just id fields.

Leave a comment