0

creating an attendance system where lecturers register and login using their lecturer code and password different lecturers teach different subjects, currently, the "subject" page displays all subjects present in the database

as such i would like the "subject" page to display only the subjects taught by the specific lecturer

how can i achieve that?

(ps. still a beginner in django..a detailed answer or resources will be highly appreciated)

Source code https://github.com/Zainab692/Fyp2/tree/master/django-project/cms

Xainy
  • 3
  • 3

1 Answers1

0

Instead of subject=Subject.objects.all() you need to filter it. Here it filters by if the "name" contains "Foo"

subject=Subject.objects.filter(lecturer_name__name__contains="Foo")

You can use this as a GET query parameter like this: Capturing URL parameters in request.GET

theptrk
  • 730
  • 9
  • 17
  • For this question, the view currently being used is under cms/views.py....the subjects are added and assigned by admin [link](https://github.com/Zainab692/Fyp2/tree/master/django-project/cms) – Xainy May 03 '22 at 17:42
  • whats the issue, is the subject not filtering? – theptrk May 05 '22 at 06:09
  • Yes I would like it filter based on user input, basically lecturer enters lecturer id and password, when he clicks on “subjects” it shd show all subjects he teaches …currently it shows all subjects in the database.. i would like it to filter based on user input – Xainy May 05 '22 at 06:48
  • what happens when you use the filter above? – theptrk May 07 '22 at 00:14