adding courses app, Course and School models
authorSeth Woodworth <seth@sethish.com>
Fri, 4 Jan 2013 00:45:54 +0000 (19:45 -0500)
committerSeth Woodworth <seth@sethish.com>
Fri, 4 Jan 2013 00:45:54 +0000 (19:45 -0500)
karmaworld/apps/courses/admin.py [new file with mode: 0644]
karmaworld/apps/courses/models.py [new file with mode: 0644]
karmaworld/settings/common.py

diff --git a/karmaworld/apps/courses/admin.py b/karmaworld/apps/courses/admin.py
new file mode 100644 (file)
index 0000000..fa8e3f0
--- /dev/null
@@ -0,0 +1,11 @@
+#!/usr/bin/python
+# -*- coding:utf8 -*-
+# Copyright (C) 2012  FinalsClub Foundation
+""" Administration configuration for courses """
+
+from django.contrib import admin
+
+import models
+
+admin.site.register(models.School)
+admin.site.register(models.Course)
diff --git a/karmaworld/apps/courses/models.py b/karmaworld/apps/courses/models.py
new file mode 100644 (file)
index 0000000..8123f9b
--- /dev/null
@@ -0,0 +1,69 @@
+#!/usr/bin/python2.7
+# -*- coding:utf8 -*-
+# Copyright (C) 2012  FinalsClub Foundation
+
+"""
+    Models for the courses django app.
+    Handles courses, and their related models
+    Courses are the first class object, they contain notes.
+    Courses have a manytoone relation to schools.
+"""
+import datetime
+
+from django.db import models
+from django.template import defaultfilters
+
+class School(models.Model):
+    """ A grouping that contains many courses """
+    name        = models.CharField(max_length=255)
+    slug        = models.SlugField(null=True)
+    location    = models.CharField(max_length=255, blank=True, null=True)
+    url         = models.URLField(max_length=511, blank=True)
+    # Facebook keeps a unique identifier for all schools
+    facebook_id = models.BigIntegerField(blank=True, null=True)
+
+    def __unicode__(self):
+        return self.name
+
+    @models.permalink
+    def get_absolute_url(self):
+        """ Not implemented yet """
+        pass
+
+    def save(self, *args, **kwargs):
+        """ Save school and generate a slug if one doesn't exist """
+        if not self.slug:
+            self.slug = defaultfilters.slugify(self.name)
+        super(School, self).save(*args, **kwargs)
+
+
+class Course(models.Model):
+    """ First class object that contains many notes.Note objects """
+    # Core metadata
+    name        = models.CharField(max_length=255)
+    desc        = models.TextField(max_length=511, blank=True, null=True)
+    slug        = models.SlugField(null=True)
+    url         = models.URLField(max_length=511, blank=True, null=True)
+
+    school      = models.ForeignKey(School) # Should this be optional ever?
+
+    academic_year   = models.IntegerField(blank=True, null=True, 
+                        default=datetime.datetime.now().year)
+    instructor_name = models.CharField(max_length=255, blank=True, null=True)
+    instructor_email = models.EmailField(blank=True, null=True)
+    updated_at    = models.DateTimeField(default=datetime.datetime.utcnow)
+    created_at    = models.DateTimeField(auto_now_add=True)
+
+    def __unicode__(self):
+        return u"{0}: {1}".format(self.name, self.school)
+
+    @models.permalink
+    def get_absolute_url(self):
+        """ Not implemented yet """
+        pass
+
+    def save(self, *args, **kwargs):
+        """ Save school and generate a slug if one doesn't exist """
+        if not self.slug:
+            self.slug = defaultfilters.slugify(self.name)
+        super(Course, self).save(*args, **kwargs)
index cb036978f2ef750872ae4a999d7ee2677fae4340..81794c9e9c4b7bedab6c4bf76507dda6acb43e03 100644 (file)
@@ -204,6 +204,7 @@ THIRD_PARTY_APPS = (
 LOCAL_APPS = (
     # file handling app
     'karmaworld.apps.notes',
+    'karmaworld.apps.courses',
 )
 
 # See: https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps