Commits

Scott Nixon committed 469294b

Added managers and model is 90% complete.

  • Participants
  • Parent commits 1a1b4d8

Comments (0)

Files changed (4)

File admin.py

Empty file added.
+from django.db import models
+
+class ActiveCourses(models.Manager):
+	def get_query_set(self):
+		return super(ActiveCourses, self).get_query_set().filter(is_published=1)
+
+class ActiveLessons(models.Manager):
+	def get_query_set(self):
+		return super(ActiveLessons, self).get_query_set().filter(is_published=1)
 from django.contrib.auth.models import User
 from django.contrib.sites.models import Site
 from django.contrib.sites.managers import CurrentSiteManager
+from managers import ActiveCourses
 
 class Courses(models.Model):
-    title = models.charfield(max_length=100,unique=True)
+    title = models.CharField(max_length=100,unique=True)
     slug = models.SlugField('Course URL', max_length=50,unique=True)
+    discussion = models.URLField()
     createdate = models.DateTimeField(auto_now_add=True,null=True)
     updatedate = models.DateTimeField(auto_now=True)
     is_published = models.BooleanField(
 		"Published", default=False, help_text="Publish this Course?"
 	)
+    
     sites = models.ManyToManyField(Site)
+    objects = models.Manager()
+    active = ActiveCourses()
+    on_site = CurrentSiteManager()
     
     @models.permalink
     def get_absolute_url(self):
 	return self.title
     
 class Lessons(models.Model):
+    course = models.ForeignKey(Courses,)
     title = models.Charfield(max_length=150,unique=True)
     content = models.TextField()
+    media = models.URLField()
     slug = models.SlugField('Lesson URL', max_length=50,unique=True)
     createdate = models.DateTimeField(auto_now_add=True,null=True)
     updatedate = models.DateTimeField(auto_now=True)
     is_published = models.BooleanField(
 		"Published", default=False, help_text="Publish this Lesson?"
 	)
+    objects = models.Manager()
+    active = ActiveLessons()
+    
     @models.permalink
     def get_absolute_url(self):
             return ('courses.views.lesson_detail', None, { 'slug': self.slug })
             
     def __unicode__(self):
             return self.title
+        
+class Media(models.Model):
+    MEDIA_TYPES = (
+	('3', 'Video'),
+	('2', 'Audio'),
+	('1', 'PDF')
+	)
+    title = models.CharField()
+    media = URLField()
+    type = models.CharField(max_length=2,choices=MEDIA_TYPES,default=1)
+    
 
 from django.shortcuts import render_to_response
 from models import Courses, Lessons
+from managers import ActiveCourses, ActiveLessons
 
 def course_index(request):
-    try:
-            c = Courses.active.all()
-    except Courses.DoesNotExist:
-            raise Http404
-    return render_to_response('courses/course_index.html', locals(),context_instance=RequestContext(request))
+    current_site = Site.objects.get_current()
+    courses_list = Courses.active.filter(sites=current_site.id)
+    
+    return render_to_response('courses/courses_index.html', locals(),context_instance=RequestContext(request))
 
 def course_detail(request, slug):
     try: