Source

HH-Courses / models.py

Full commit
from django.db import models
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, ActiveLessons
from autoslug import AutoSlugField

class Courses(models.Model):
    title = models.CharField(max_length=100,unique=True)
    summary = models.TextField()
    slug = AutoSlugField(populate_from='title', always_update=True, verbose_name='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()
    
    class Meta:
        verbose_name_plural = "Courses"
        
    @models.permalink
    def get_absolute_url(self):
	return ('courses.views.course_detail', None, { 'slug': self.slug })
        
    def __unicode__(self):
	return self.title
    
class Lessons(models.Model):
    course = models.ForeignKey(Courses)
    title = models.CharField(max_length=150,unique=True)
    summary = models.TextField()
    content = models.TextField()
    slug = AutoSlugField(populate_from='title', always_update=True, verbose_name='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()
    
    class Meta:
        verbose_name_plural = "Lessons"
    
    @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')
	)
    lesson = models.ForeignKey(Lessons)
    title = models.CharField(max_length=100,)
    media = models.URLField()
    type = models.CharField(max_length=2,choices=MEDIA_TYPES,default=1)
    createdate = models.DateTimeField(auto_now_add=True,null=True)
    updatedate = models.DateTimeField(auto_now=True)
    
    class Meta:
        verbose_name_plural = "Media"
    
    def __unicode__(self):
        return self.title