diff options
author | Parth Buch | 2012-06-21 18:27:21 +0530 |
---|---|---|
committer | Parth Buch | 2012-06-21 18:27:21 +0530 |
commit | 3f342f3ac36cfbf1cb68ccb767a76aba327a8326 (patch) | |
tree | 2caef218628bcde6728d591f19491a6b8d36e933 /stapp/video | |
parent | bb1c3bda3a6baad8d8eb9edd2cadf49674972b58 (diff) | |
download | stproject-3f342f3ac36cfbf1cb68ccb767a76aba327a8326.tar.gz stproject-3f342f3ac36cfbf1cb68ccb767a76aba327a8326.tar.bz2 stproject-3f342f3ac36cfbf1cb68ccb767a76aba327a8326.zip |
Added created and modified date, passing modules to the home page view
Diffstat (limited to 'stapp/video')
-rw-r--r-- | stapp/video/models.py | 10 | ||||
-rw-r--r-- | stapp/video/views.py | 17 |
2 files changed, 21 insertions, 6 deletions
diff --git a/stapp/video/models.py b/stapp/video/models.py index aa675b1..56cb5fe 100644 --- a/stapp/video/models.py +++ b/stapp/video/models.py @@ -1,5 +1,6 @@ from django.db import models from django.contrib.auth.models import User +import datetime class Video(models.Model): """Videos to be uploaded..""" @@ -14,7 +15,14 @@ class Video(models.Model): class Module(models.Model): name = models.CharField(max_length=128) description = models.TextField() - vidio_list = models.ManyToManyField(Video) + video_list = models.ManyToManyField(Video) + created = models.DateTimeField(auto_now_add=True) + modified = models.DateTimeField() + + def save(self, *args, **kwargs): + ''' On save, update timestamps ''' + self.modified = datetime.datetime.today() + super(Module, self).save(*args, **kwargs) def __unicode__(self): return self.name diff --git a/stapp/video/views.py b/stapp/video/views.py index 1db66aa..3ec1953 100644 --- a/stapp/video/views.py +++ b/stapp/video/views.py @@ -1,13 +1,20 @@ from django.http import HttpResponse from django.template import RequestContext -from django.shortcuts import render_to_response, get_object_or_404, redirect -from video.models import Video +from django.shortcuts import render, get_object_or_404, redirect +from video.models import Video, Module def show(request): videos = Video.objects.all() if len(videos) == 0 : return HttpResponse("No videos in Database...") - play_video = Video.objects.latest('created') - vids = { 'videos' : videos , 'play' : play_video} - return render_to_response('video/list_videos.html', vids) + + #Get the latest video to display on the front page + latest_video = Video.objects.latest('created') + + #Get last three modified modules + latest_modules = Module.objects.order_by('-modified')[0:3] + + + context = { 'modules' : latest_modules , 'play' : latest_video} + return render(request, 'video/home.html', context) |