The data inside a model can be retrieved by using the all
function in Django.
Person.objects.all()
It returns all the values present in the database table as Model objects. You can store those values in a variable and use a loop to access individual objects in it.
p=Person.objects.all()
for i in p:
print(i.first_name, i.last_name, i.birth_date)
If you want to get them in a dictionary
form, after applying the all
function, you can use the values
function to get them as dictionaries
.
Person.objects.all().values()
This can be used to retrieve all the data from models.