Google News
logo
Django - Interview Questions
How to view and filter items from the database?
In order to view all the items from your database, you can make use of the ‘all()’ function in your interactive shell as follows:
 
* XYZ.objects.all()     where XYZ is some class that you have created in your models

To filter out some element from your database, you either use the get() method or the filter method as follows:
 
* XYZ.objects.filter(pk=1)
* XYZ.objects.get(id=1)
Advertisement