I'm using the Python shell in Django to make some queries. The results keep getting truncated. I get the message, "remaining elements truncated." How can I see all the results? Or, how can I write the results to a file?
A:
Say your query is:
>>> Foo.objects.all()
Instead try:
>>> for x in Foo.objects.all(): print x
Or to dump them to a file:
>>> f = open('your_filename','w')
>>> for x in Foo.objects.all(): f.write(u'%s\n' % x)
>>> f.close()
Matthew Christensen
2010-07-14 18:47:51
+2
A:
Querysets do this automatically when you just output them in the shell - which implictly calls repr
on them. If you call list
on the queryset instead, that will output everything:
list(MyModel.objects.all())
Note that you don't need to do this within your code, this is just for output within the shell. Obviously, beware of doing this on a model with a very large number of entries.
Daniel Roseman
2010-07-14 18:48:22
That works. Thanks!
dhh9
2010-07-14 19:03:32