python - How to add an model instance to a django queryset? -
python - How to add an model instance to a django queryset? -
it seems django queryset behaves somehow python list.
but doesn't back upwards list's .append() method know.
what want like:
from my_django_app.models import mymodel queryset = mymodel.objects.none() queryset.append(mymodel.objects.first()) ## no list's .append() method! is there way add together model instance existing queryset?
no. queryset representation of query - hence name - not arbitrary collection of instances.
if need actual queryset rather list, seek accumulating ids of objects need , getting objects via __in query:
list_of_ids = [] list_of_ids.append(my_id) ... queryset = mymodel.objects.filter(id__in=list_of_ids) this isn't efficient, though.
python django
Comments
Post a Comment