用于构建“新闻源”的Django方式/“状态更新” /“活动流” [英] Django-way for building a "News Feed" / "Status update" / "Activity Stream"

查看:177
本文介绍了用于构建“新闻源”的Django方式/“状态更新” /“活动流”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个可重用的Django应用程序来处理用户的状态更新。很像Facebook的新闻资讯。

I'd like to create a reusable Django app that handles status updates of the Users. Much like facebook's "news feed".

使用案例包括,例如:


  • 教授可以根据具体的日期创建作业,并且每个学生都可以在新闻Feed上看到作品的创建,简短说明,到期日期以及链接以查看完整说明

  • 他还可以上传他对学生有趣的新PDF。在新闻提要中,应该显示有关这方面的信息,例如pdf的说明,下载的链接和预览链接

  • 可以发布到YouTube视频的链接,新闻稿显示一个小缩略图,并点击,使用javascript 嵌入视频,用户可以观看它立即就可以了。

  • A Professor can create an Assignment due to an specific date and every student can see on the news feed that the assignment was created, with a short description, the date that it's due and a link to see the full description.
  • He also can upload a new PDF that he finds interesting for his students. On the news feed, the info regarding this should be displayed, eg, the description of the pdf, an link to download and a link to preview it.
  • A link to a YouTube video can be posted and on the News Feed is displayed an small thumbnail and, with a click, the video is embbeded using javascript and the user can watch it right away.

一个问题是如何处理不同类型的更新并显示正确的html代码段。另一个更重要的是如何设计这个Django方式的模型。

One concern is how to handle different kinds of Updates and display the correct "html snippet" for it. The other, which is more important, is how to design the Models of this "Django way".

关于前者,我可以想到两种做法:

About the former, I could think of two ways of doing it:


  1. 使用模型继承;

  2. 使用泛型关系

我在发布之前搜索过,但我没有找到任何东西。我检查了Pinax,看看它们是否已经实现,但是没有。所以,我在这里寻找更多关于如何处理这个问题的建议。

I searched before posting here, but I didn't find anything. I checked Pinax to see if they had it implemented, but they don't. So, I'm here looking for more suggestions on how to handle this in a nice and non-hacky way.

提前感谢,

推荐答案

我可以通过两种方式思考:

I can think in two ways:

首先,也许你必须使 feed 为您的模型Assigments,PdfFiles和Youtube链接,并使用库 feedparser 将其嵌入到您的新闻视图中,这是一种简单的方法,因为您可以在模板中定义,每一种新活动的代码。

First, maybe you must make feeds for your models Assigments, PdfFiles, and Youtube link, and use the library feedparser for embed tthat in your news views, this is the easy way because you can define in templates, the code for each kind of new activity.

我可以想到的第二件事是使一个类活动

The second thing i can think is make a class Activity:

class Activity(models.Model):
    date = models.DateTimeField(auto_now_add = True)
    content_type = models.ForeignKey(ContentType)
    object_id = models.PositiveIntegerField()
    content_object = generic.GenericForeignKey('content_type', 'object_id')

通过信号每当您有新的分类或pdf上传或YouTube链接时,都会创建一个新的活动实例,并且对于每个类,使用诸如 render_to_html 的方法,以这种方式在您的视图中,您可以进行以下活动,并调用方法render_to_html

And through the signals make a new instance of Activity every time you have a new assigment or pdf upload or youtube link, and for each class make a method like render_to_html, in this way in your view, you can make a for over Activities and call the method render_to_html

这篇关于用于构建“新闻源”的Django方式/“状态更新” /“活动流”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆