67👍
✅
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.
3👍
The top answer returns an error for me in 2020:
Error in argument: '(MyModel.objects.all())'
What works for me is just iterating over the Queryset as a list comprehension:
[i for i in MyModel.objects.all()]
- [Django]-How to fetch static CSS files with django on IIS?
- [Django]-Reload django object from database
- [Django]-Timezone.now() vs datetime.datetime.now()
2👍
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()
- [Django]-Count number of records by date in Django
- [Django]-Django setting environment variables in unittest tests
- [Django]-Reverse for '*' with arguments '()' and keyword arguments '{}' not found
Source:stackexchange.com