tags:

views:

112

answers:

2

I'm working on a new Django project, and the client wants to "feature" content on the homepage and a few other sections of the website. Content in this case could be a blog post, an event, a news story, etc. Each item would have a "start featuring" datetime and an "stop featuring" datetime.

I've done this a few different ways in the past, but wonder if anybody has any great methods of archiving this.

+6  A: 

Have you looked at the contenttypes framework? You could set up a FeaturedItem model, with start and end datetimes, and a generic foreign key. This allows the relationship to be with any model.

If you heavily feature objects from particular models, look at the section on reverse generic relations.

Alasdair
That's actually one of the methods I've used in the past. The one usability problem we've ran into is the visibility of what's currently featured, but I'll probably just create a "read-only" view of all active the FeaturedItems. Thanks!
Chip Tol
A: 

I'm trying something similar, using the contenttypes framework but the problem comes when displaying the relationship in the admin area. I've been trying to hack this together to simply show a checkbox with "Featured?" next to it.

class FeaturedContent(models.Model):
    content_type = models.ForeignKey(ContentType)
    object_id = models.PositiveIntegerField()
    content_object = generic.GenericForeignKey('content_type', 'object_id')

I'm not yet clear on how to implement the checkbox.

Crungmungus