Facebook wall like application in Django - part 1
Creating Facebook Wall-like or Twitter-like Django application for small social, intranet or collaboration sites. Part 1 - playing with models and queries.
Facebook is the leading social website and it's functionality or user interface is well known. Many smaller websites try to reuse ideas from Facebook to provide users with UI that they know and which is easy to use and functional. Designing a social site, collaboration web application or company intranet sites we can think about adding a microblog Twitter-like or Facebook Wall-like application. Lets do some initial implementation in Django.
So let say we want to make a company user Wall application. Users are grouped in departments/categories and we want to let users post messages to friends, department workers, public and private messages. Also multimedia handling is required - post a URL and the wall will generate for example YT clip player. Lets start with user profile models:
We have two models - Department model and the true profile model - "Profile". Most important fields are "Department" and "Friends". Also the profiles have to be generated, updated, but this isn't the point of this article.As for content models for the wall, lest look at simple multimedia model:
We have tree types of multimedias - links, images, and video clips from YouTube, Vimeo etc. The "text" field will contain ready to display HTML code for given media. For finished application user would enter the URL and by AJAX request the django app would parse the URL (fetch the url) and returned required data (player code, website title, image thumbnail etc.).Main element of a wall or microblog is the message. We need a message model like this one:
So we have "message" field for the text users submits, "author" field to identify him and some fields - "dep" and "message_friends" copied at the time of creation. Those fields will help getting proper messages on a user wall. "privacy_type" fields sets the message privacy. If the message is private then it has to have "private_recipients". Using "in_reply_to" field we can reuse this model for commenting other messages. Main messages will have null for this field.