Fetching data using Foreign key

How do i retrieve Course objects using semId as the search key…
Also using filter gives empty queryset…TIA


class Semester(models.Model):
    def __str__(self):
        return str(self.semId)
class Course(models.Model):
    def __str__(self):
        return str(self.courseName)


def sem(request,id):
    for o in ob:
    return render(request,'sem.html')

Error using get

DoesNotExist at /sem/8/
Course matching query does not exist.
Request Method:	GET
Request URL:
Django Version:	4.1.1
Exception Type:	DoesNotExist
Exception Value:	
Course matching query does not exist.
Exception Location:	C:\Users\ASUS\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\models\query.py, line 650, in get
Raised during:	emnei.views.sem
Python Executable:	C:\Users\ASUS\AppData\Local\Programs\Python\Python310\python.exe
Python Version:	3.10.7
Python Path:	
Server time:	Sat, 17 Sep 2022 12:24:47 +0000

See Making queries | Django documentation | Django

If a filter function is returning an empty queryset, then either you don’t have the data in your database that you think is there, or you’ve written your query incorrectly.

(Note: If you’re getting an error message - which I believe you may be - it’s always helpful to include the complete error in your posts.)

updated the error message.
Also using filter returns empty queryset…
I guess the thing i am missing here is accessing the semId which is a foreign key in the COurse model

See Lookups that span relationships.

reveal how you are trying things right now to getthe error, you should show what you’re doing even if it isn’t working