I have a website with different kinds of activities:
- Lessons ;
- Exercises ;
- Quizzes.
So far, each type of activity corresponds to a specific Model and a table in the database. I would like to create an ordered path through these activities. For instance:
- Lesson 1
- then Exercise 1
- then Lesson 2
- then Quizz 1
- etc.
I am considering to create a model named Activity that would store the following data:
- A number: the number of the activity in the path ;
- A One-To-One relationship to one given activity (lesson, exercise, quizz etc.).
(1) I have seen that Django offers a GenericForeignKey to handle many-to-one relationship to different kinds of models, like many comments associated to a single lesson or a single exercise. Is there something similar for Generic OneToOne relationship?
(2) I would like to track the progress of my users. To do so, I am considering having a many-to-many relationship called "done_activities" built in my User model and linked to my Activity model. Do you think this is an efficient way of approaching the problem ?
I'm not sure you would need or want self-referential fields in this case. Consider the following structure as an example. I do not propose this 'in stone' as THE solution, but more to spur your own ideas about the solution you need. Please note that I'm leaving out
__str__methods and such for brevity:In this schema scenario, the following are true:
Activitys are all tracked and stored together on a single table, organized by type, and each one can have its own description.Programs are stored on their own model, and represent a named object that unites all their constituent activities.ProgramActivityconnects activities to specific programs, and allows you to set the order in the path for that activity relative to the program, and change it easily if you have to. You can easily queryactivities = ProgramActivity.objects.filter(program=some_program).order_by('path_order')and get a very usable list of a Program's activities.UserProgrammodel records a User's "enrollments" and progress in each, in this example, by percentage of the program completed.This is just one possible approach. You may, for example, want to create an activity type table instead of a list dropdown, which may be a more robust way of managing activities over time.