Commits

Scott Nixon committed 1057744

Added migrations. Ability to add courses, lessons, and media.

  • Participants
  • Parent commits 469294b

Comments (0)

Files changed (8)

 .Python
 .DS_Store
 Courses.kpf
+.pyc
+
+from django.contrib import admin
+from django.contrib.sites.models import Site
+from django.contrib.sites.managers import CurrentSiteManager
+from models import Courses, Lessons, Media
+
+class MediaInline(admin.TabularInline):
+	model = Media
+	extra = 2
+
+class CoursesAdmin(admin.ModelAdmin):		
+	fields = ['title', 'discussion', 'summary', 'is_published', 'sites']
+	list_display = ['title', 'is_published',]
+	list_filter = ['createdate']
+	date_hierarchy = 'createdate'
+	search_fields = ['title']
+
+class LessonsAdmin(admin.ModelAdmin):		
+	fields = ['course', 'title', 'summary', 'content', 'is_published']
+	list_display = ['title', 'is_published',]
+	list_filter = ['createdate']
+	date_hierarchy = 'createdate'
+	search_fields = ['title']
+        inlines = [ MediaInline,]
+        
+class MediaAdmin(admin.ModelAdmin):		
+	fields = ['lesson', 'title', 'media', 'type']
+	list_display = ['title', 'media',]
+	list_filter = ['createdate']
+	date_hierarchy = 'createdate'
+	search_fields = ['title']   
+
+
+admin.site.register(Courses, CoursesAdmin)
+admin.site.register(Lessons, LessonsAdmin)
+#admin.site.register(Media, MediaAdmin)
+        

migrations/0001_initial.py

+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+class Migration(SchemaMigration):
+
+    def forwards(self, orm):
+        
+        # Adding model 'Courses'
+        db.create_table('courses_courses', (
+            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+            ('title', self.gf('django.db.models.fields.CharField')(unique=True, max_length=100)),
+            ('slug', self.gf('autoslug.fields.AutoSlugField')(unique=True, max_length=50, populate_from=None, unique_with=(), db_index=True)),
+            ('discussion', self.gf('django.db.models.fields.URLField')(max_length=200)),
+            ('createdate', self.gf('django.db.models.fields.DateTimeField')(auto_now_add=True, null=True, blank=True)),
+            ('updatedate', self.gf('django.db.models.fields.DateTimeField')(auto_now=True, blank=True)),
+            ('is_published', self.gf('django.db.models.fields.BooleanField')(default=False, blank=True)),
+        ))
+        db.send_create_signal('courses', ['Courses'])
+
+        # Adding M2M table for field sites on 'Courses'
+        db.create_table('courses_courses_sites', (
+            ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
+            ('courses', models.ForeignKey(orm['courses.courses'], null=False)),
+            ('site', models.ForeignKey(orm['sites.site'], null=False))
+        ))
+        db.create_unique('courses_courses_sites', ['courses_id', 'site_id'])
+
+        # Adding model 'Lessons'
+        db.create_table('courses_lessons', (
+            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+            ('course', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['courses.Courses'])),
+            ('title', self.gf('django.db.models.fields.CharField')(unique=True, max_length=150)),
+            ('content', self.gf('django.db.models.fields.TextField')()),
+            ('slug', self.gf('autoslug.fields.AutoSlugField')(unique=True, max_length=50, populate_from=None, unique_with=(), db_index=True)),
+            ('createdate', self.gf('django.db.models.fields.DateTimeField')(auto_now_add=True, null=True, blank=True)),
+            ('updatedate', self.gf('django.db.models.fields.DateTimeField')(auto_now=True, blank=True)),
+            ('is_published', self.gf('django.db.models.fields.BooleanField')(default=False, blank=True)),
+        ))
+        db.send_create_signal('courses', ['Lessons'])
+
+        # Adding model 'Media'
+        db.create_table('courses_media', (
+            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+            ('lesson', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['courses.Lessons'])),
+            ('title', self.gf('django.db.models.fields.CharField')(max_length=100)),
+            ('media', self.gf('django.db.models.fields.URLField')(max_length=200)),
+            ('type', self.gf('django.db.models.fields.CharField')(default=1, max_length=2)),
+        ))
+        db.send_create_signal('courses', ['Media'])
+
+
+    def backwards(self, orm):
+        
+        # Deleting model 'Courses'
+        db.delete_table('courses_courses')
+
+        # Removing M2M table for field sites on 'Courses'
+        db.delete_table('courses_courses_sites')
+
+        # Deleting model 'Lessons'
+        db.delete_table('courses_lessons')
+
+        # Deleting model 'Media'
+        db.delete_table('courses_media')
+
+
+    models = {
+        'courses.courses': {
+            'Meta': {'object_name': 'Courses'},
+            'createdate': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'null': 'True', 'blank': 'True'}),
+            'discussion': ('django.db.models.fields.URLField', [], {'max_length': '200'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'is_published': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
+            'sites': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['sites.Site']", 'symmetrical': 'False'}),
+            'slug': ('autoslug.fields.AutoSlugField', [], {'unique': 'True', 'max_length': '50', 'populate_from': 'None', 'unique_with': '()', 'db_index': 'True'}),
+            'title': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '100'}),
+            'updatedate': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'})
+        },
+        'courses.lessons': {
+            'Meta': {'object_name': 'Lessons'},
+            'content': ('django.db.models.fields.TextField', [], {}),
+            'course': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['courses.Courses']"}),
+            'createdate': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'null': 'True', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'is_published': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
+            'slug': ('autoslug.fields.AutoSlugField', [], {'unique': 'True', 'max_length': '50', 'populate_from': 'None', 'unique_with': '()', 'db_index': 'True'}),
+            'title': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '150'}),
+            'updatedate': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'})
+        },
+        'courses.media': {
+            'Meta': {'object_name': 'Media'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'lesson': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['courses.Lessons']"}),
+            'media': ('django.db.models.fields.URLField', [], {'max_length': '200'}),
+            'title': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'type': ('django.db.models.fields.CharField', [], {'default': '1', 'max_length': '2'})
+        },
+        'sites.site': {
+            'Meta': {'object_name': 'Site', 'db_table': "'django_site'"},
+            'domain': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+        }
+    }
+
+    complete_apps = ['courses']

migrations/0002_auto__add_field_media_createdate__add_field_media_updatedate.py

+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+class Migration(SchemaMigration):
+
+    def forwards(self, orm):
+        
+        # Adding field 'Media.createdate'
+        db.add_column('courses_media', 'createdate', self.gf('django.db.models.fields.DateTimeField')(auto_now_add=True, null=True, blank=True), keep_default=False)
+
+        # Adding field 'Media.updatedate'
+        db.add_column('courses_media', 'updatedate', self.gf('django.db.models.fields.DateTimeField')(auto_now=True, default=datetime.date(2010, 8, 20), blank=True), keep_default=False)
+
+
+    def backwards(self, orm):
+        
+        # Deleting field 'Media.createdate'
+        db.delete_column('courses_media', 'createdate')
+
+        # Deleting field 'Media.updatedate'
+        db.delete_column('courses_media', 'updatedate')
+
+
+    models = {
+        'courses.courses': {
+            'Meta': {'object_name': 'Courses'},
+            'createdate': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'null': 'True', 'blank': 'True'}),
+            'discussion': ('django.db.models.fields.URLField', [], {'max_length': '200'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'is_published': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
+            'sites': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['sites.Site']", 'symmetrical': 'False'}),
+            'slug': ('autoslug.fields.AutoSlugField', [], {'unique': 'True', 'max_length': '50', 'populate_from': 'None', 'unique_with': '()', 'db_index': 'True'}),
+            'title': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '100'}),
+            'updatedate': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'})
+        },
+        'courses.lessons': {
+            'Meta': {'object_name': 'Lessons'},
+            'content': ('django.db.models.fields.TextField', [], {}),
+            'course': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['courses.Courses']"}),
+            'createdate': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'null': 'True', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'is_published': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
+            'slug': ('autoslug.fields.AutoSlugField', [], {'unique': 'True', 'max_length': '50', 'populate_from': 'None', 'unique_with': '()', 'db_index': 'True'}),
+            'title': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '150'}),
+            'updatedate': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'})
+        },
+        'courses.media': {
+            'Meta': {'object_name': 'Media'},
+            'createdate': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'null': 'True', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'lesson': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['courses.Lessons']"}),
+            'media': ('django.db.models.fields.URLField', [], {'max_length': '200'}),
+            'title': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'type': ('django.db.models.fields.CharField', [], {'default': '1', 'max_length': '2'}),
+            'updatedate': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'})
+        },
+        'sites.site': {
+            'Meta': {'object_name': 'Site', 'db_table': "'django_site'"},
+            'domain': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+        }
+    }
+
+    complete_apps = ['courses']

migrations/0003_auto__add_field_lessons_summary__add_field_courses_summary.py

+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+class Migration(SchemaMigration):
+
+    def forwards(self, orm):
+        
+        # Adding field 'Lessons.summary'
+        db.add_column('courses_lessons', 'summary', self.gf('django.db.models.fields.TextField')(default=datetime.date(2010, 8, 20)), keep_default=False)
+
+        # Adding field 'Courses.summary'
+        db.add_column('courses_courses', 'summary', self.gf('django.db.models.fields.TextField')(default=datetime.date(2010, 8, 20)), keep_default=False)
+
+
+    def backwards(self, orm):
+        
+        # Deleting field 'Lessons.summary'
+        db.delete_column('courses_lessons', 'summary')
+
+        # Deleting field 'Courses.summary'
+        db.delete_column('courses_courses', 'summary')
+
+
+    models = {
+        'courses.courses': {
+            'Meta': {'object_name': 'Courses'},
+            'createdate': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'null': 'True', 'blank': 'True'}),
+            'discussion': ('django.db.models.fields.URLField', [], {'max_length': '200'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'is_published': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
+            'sites': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['sites.Site']", 'symmetrical': 'False'}),
+            'slug': ('autoslug.fields.AutoSlugField', [], {'unique': 'True', 'max_length': '50', 'populate_from': 'None', 'unique_with': '()', 'db_index': 'True'}),
+            'summary': ('django.db.models.fields.TextField', [], {}),
+            'title': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '100'}),
+            'updatedate': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'})
+        },
+        'courses.lessons': {
+            'Meta': {'object_name': 'Lessons'},
+            'content': ('django.db.models.fields.TextField', [], {}),
+            'course': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['courses.Courses']"}),
+            'createdate': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'null': 'True', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'is_published': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
+            'slug': ('autoslug.fields.AutoSlugField', [], {'unique': 'True', 'max_length': '50', 'populate_from': 'None', 'unique_with': '()', 'db_index': 'True'}),
+            'summary': ('django.db.models.fields.TextField', [], {}),
+            'title': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '150'}),
+            'updatedate': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'})
+        },
+        'courses.media': {
+            'Meta': {'object_name': 'Media'},
+            'createdate': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'null': 'True', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'lesson': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['courses.Lessons']"}),
+            'media': ('django.db.models.fields.URLField', [], {'max_length': '200'}),
+            'title': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'type': ('django.db.models.fields.CharField', [], {'default': '1', 'max_length': '2'}),
+            'updatedate': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'})
+        },
+        'sites.site': {
+            'Meta': {'object_name': 'Site', 'db_table': "'django_site'"},
+            'domain': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+        }
+    }
+
+    complete_apps = ['courses']

migrations/__init__.py

Empty file added.
 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
+from managers import ActiveCourses, ActiveLessons
+from autoslug import AutoSlugField
 
 class Courses(models.Model):
     title = models.CharField(max_length=100,unique=True)
-    slug = models.SlugField('Course URL', max_length=50,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)
     
-    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)
+    course = models.ForeignKey(Courses)
+    title = models.CharField(max_length=150,unique=True)
+    summary = models.TextField()
     content = models.TextField()
-    media = models.URLField()
-    slug = models.SlugField('Lesson URL', max_length=50,unique=True)
+    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(
     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 })
 	('2', 'Audio'),
 	('1', 'PDF')
 	)
-    title = models.CharField()
-    media = URLField()
+    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
     
 
 from django.conf.urls.defaults import *
 
 urlpatterns = patterns('courses.views',
-	url(r'^courses/$', view='course_index', name='course_index'),
-	url(r'^course/(?P<slug>.*)/$', view='course_detail', name='course_detail'),
+	url(r'^$', view='course_index', name='course_index'),
+	url(r'^(?P<slug>.*)/$', view='course_detail', name='course_detail'),
 	url(r'^lesson/(?P<slug>.*)/$', view='lesson_detail', name='lesson_detail'),
 )