The Python Oracle

Monitoring User Activity in Django

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Meditation

--

Chapters
00:00 Monitoring User Activity In Django
01:09 Accepted Answer Score 2
01:42 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.