Abraham
Abraham

Reputation: 3

How can I track a user events in Django?

I'm building a small social site, and I want to implement an activity stream in a users profile to display event's like commenting, joining a group, posting something, and so on. Basically, I'm trying to make something similar to a reddit profile that shows a range of user activity.

I'm not sure how I'd do this in Django though. I thought of maybe making an "Activity" model that's OneToOne with their account, and update it through MiddleWare.

Anyone here have a suggestion? Away I could actually implement this in a nice way?

Upvotes: 0

Views: 1227

Answers (2)

Enrico Carlesso
Enrico Carlesso

Reputation: 6934

In my opinion, you should do exactly what you're saying, that is create the model Activity, which has a foreignKey to User which you will populate triggering the things you'll find 'interesting'.

This practice, even if redundant, will speed up your page generation, and you can add a custom field which will hold the text you want to display, and also you can keep track of what generate the Activity.

Upvotes: 1

Ned Batchelder
Ned Batchelder

Reputation: 375594

You pretty much need to use an explicit Activity model, then create instances of those records in the view functions that perform the action.

I think you'll find that any other more automatic way of tracking activity would be too inflexible: it would record events at the wrong level of detail, and prevent you from describing events in a way that the user wants to see them.

Upvotes: 2

Related Questions