For this project, we'll use the Django Content Types framekwork to add different types of tweets to our Twitter clone. Specifically, we'll add image and video tweets to our regular text tweet. We'll need to make our Tweet model support different types of tweet, that should be generic. By "generic" we mean you can't hardcode a image_url
field to the Tweet
model. You'll need somehow make use of the model classes ImageTweet
and VideoTweet
from twitter/models.py
. As usual, you'll find out that this process is really simple using the correct Django helper; in this case you might want to take a look at Generic Relations.
Once you finish implementing your project to support images and videos, try extending the project to support a new type of tweet GistTweet
that receives a Github's Gist URL. If you've used generic relations, it's going to be simple to extend it.
As usual, we have our regular Twitter feed view:
But this time, we'll have the option of creating different type of tweets (image, video, or the usual text tweet):
The default type is text:
When you select the "Image Type" a form input will be shown to enter an image URL:
When you choose to tweet an image, you should see it in the template:
A Video tweet should be created in the same way: