from myapp.models import Person # retrieve all person objects persons = Person.objects.all() # loop through and print the name of each person for person in persons: print(person.name)
from django.contrib.auth.models import User # retrieve all active users active_users = User.objects.filter(is_active=True) # count the number of active users num_active_users = active_users.count()In this example, we import the User model from the `django.contrib.auth.models` package and use the `filter()` method to retrieve all active users. We then use the `count()` method to determine the number of active users. Package library: Django