The Python Oracle

Monitoring User Activity in Django

Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn

--

Music by Eric Matyas
https://www.soundimage.org
Track title: Puddle Jumping Looping

--

Chapters
00:00 Question
01:35 Accepted answer (Score 2)
02:19 Thank you

--

Full question
https://stackoverflow.com/questions/4016...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #django

#avk47



ACCEPTED ANSWER

Score 2


If you want to monitor the reading progress for every user, you can't have the completed fields on the Chapter, SubChapter and SubSection models, you need a new one related to the user. I would do something like this:

class ReadingProgress(models.Model):
    user = models.ForeignKey(User)
    completed_chapter = models.ForeignKey(Chapter)
    completed_subchapter = models.ForeignKey(SubChapter)
    completed_subsection = models.ForeignKey(SubSection)

If you have different books, you should add foreign keys to the book model as well.

Then in the views that fetch the chapters, sections and so on, you can get the ReadingProgress object for the specific user (and book?) and set the corresponding values.