开发者

"Featuring" content in a Django website

开发者 https://www.devze.com 2022-12-09 19:02 出处:网络
I\'m working on a 开发者_JAVA技巧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

I'm working on a 开发者_JAVA技巧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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消