[Django]-Django – converting object to queryset without querying database

3👍

Assuming the test.html template needs a QuerySet you’re code is fine the way it is. Refetching the data is inefficient, but there is no documented way to populate a QuerySet except through the database.

You don’t give an example test.html but in many cases you could skip the QuerySet and pass a list instead, for example:

obj = MyModelSerializer(data)
obj.save()
return render(request, 'test.html', {'qs': [obj]})

Leave a comment