[Answered ]-Listview must return only the courses that student have puchased in django

1👍

You should use reverse relation for such query. Start with adding related_name to purchased field of User:

class User(AbstractUser):
    ...
    purchased = models.ManyToManyField(Course, blank=True, related_name="buyers")

Then you can easily use that name in making queries based on relations:

Course.objects.filter(buyers=self.request.user).order_by('title')

More about queries

Leave a comment