views:

28

answers:

1

I'm trying to model a "what's hot right now" like function for a video library (i.e a Most-viewed related to time - Clustering views (in time) will cause a higher rating), but I can't quite get my head around how do to it properly in Django without causing a multitude of database queries. I realize there's no one right answer to this, but I'm at a complete loss. The list will vary on categories but will be displayed in all views on the site, so I can't just hack together a solution - it needs to be fairly optimal.

I'm pretty new to Django so if there's any trick I could employ to make this less of a problem I'd love to know.

I should point out that I can add fields to the models at will, as we're still working on the specification for the site.

A: 

You could use a table (model) for clusters, like one for days, one for weeks, one for months, etc, and store viewcount there instead of in the video's model itself, then you just reference it. Like:

Months.objects().filter(month=this_month).order_by(viewcount)[0].video
Attila Oláh