[Answered ]-Accessing the values of a ManyToManyField in Django

1👍

user.enrollments is a manager, just like Course.objects is a manager. You can create a QuerySet of the objects by using the .all() method [Django-doc]:

user.enrollments.all()  # collection of Courses user is enrolled in

and we can query for the users enrolled in a Course object course:

course.user.all()  # users enrolled in course

Leave a comment