2

How would you cope with following problem? There are teachers, and students. Student can not view pages dedicated to teachers, and teachers can view pages dedicated to students. Teachers can have list of just students they teach. I want both teachers and students to use build in User to let them login.

I have following ideas:

Separate table for teacher and student with foreign key to build in user? - but the question is, can I easily render pages and distinguish who is teacher and who is student.

Permissions? Groups? and just one table Users? But to be honest I did not find the way how could I manage to achieve that what I mentioned at the beginning.

Would be grateful for any ideas, suggestions and comments, as I am thinking of it for HOURS!

danb333
  • 1,244
  • 2
  • 10
  • 15

1 Answers1

5

As a rough start:

User Table

  • user id (primary key)
  • details (name, address, phone --i.e. common to a user of the system whether student or teacher.)

Student Table

  • user id (foreign key relationship to user table)
  • any student specific details (enrolment date, homeroom, etc.)

Teacher Table

  • a user id (foreign key relationship to user table)
  • teacher specific stuff (seniority, salary, etc.)

Classes Table

  • a class id (primary key).
  • details of the class

Grades Table

  • a user id (foreign)
  • a class id (foreign) -> these two keys used for doing a grade query.
  • a grade

(if a student can take a class multiple times, and have multiple grades, the grades table will need to have its own key, possibly with sequence type to establish the order in which they received them).

Your page that is displaying the user can query the user table display that information, followed by their student or teacher specific information. If its possible for a student to be a teacher, then you're able to do that too.

John Carter
  • 6,752
  • 2
  • 32
  • 53
  • Thank you very much for such a precise answer! – danb333 Sep 19 '12 at 13:43
  • No problem. Hope it helps. It should be flexible enough to accommodate any customizations you may need to make. You could also add a permissions table (keyed to user id) if you need a more fine-grained access control system. – John Carter Sep 19 '12 at 15:30
  • Thank you very much John for help:) Django has built in groups with permissions, so that should solve problem. Btw, what do you think of about 1t1 relationship of student with user (and teacher with user), and using user id as a primary key? – danb333 Sep 19 '12 at 18:43
  • I think that's perfectly fine. The only extra considerations are for situations where a teacher is also a student, or if a student later becomes a teacher. Using userid as a primary key by your system gives you the chance to keep it private, and a table like students can have an additional key (like "student id") which is 'public' while still maintaining the foreign key relationship to the users table. – John Carter Sep 19 '12 at 19:51