json - Django - Query models where id equals attribute on python list -



json - Django - Query models where id equals attribute on python list -

i need query models id matches 'id' attribute of json array, that:

i have 3 saved model objects respective id's:

id 1 id 3 id 4

i have json array that:

[{'id' : 1}, {'id' : 2}, {'id' : 5}]

i want filter in way:

model.objects.filter('objects id not listed in json array')

the result of filter should list models objects id not in json:

result = [model_pk=3, model_pk=4]

any ideas?

you can utilize exclude method accomplish that:

ids = [i['id'] in json_array] qs = model.objects.exclude(id__in=ids)

python json django django-models django-filter

Comments

Popular posts from this blog

c# - ASP.NET MVC Sequence contains no matching element -

java - Parsing XML, skip certain tags -

rest - How to invalidate user session on inactivity in a stateless server? -