summaryrefslogtreecommitdiff
path: root/app/classes/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'app/classes/models.py')
-rw-r--r--app/classes/models.py96
1 files changed, 96 insertions, 0 deletions
diff --git a/app/classes/models.py b/app/classes/models.py
new file mode 100644
index 0000000..b10c863
--- /dev/null
+++ b/app/classes/models.py
@@ -0,0 +1,96 @@
+import datetime
+import os
+
+from django.dispatch import receiver
+from django.contrib.gis.db import models
+from django.db.models.signals import post_save
+from django.contrib.contenttypes.fields import GenericRelation, GenericForeignKey
+from django.contrib.contenttypes.models import ContentType
+from django.contrib.sites.models import Site
+from django.urls import reverse
+from django.utils.functional import cached_property
+from django.apps import apps
+from django.conf import settings
+from django.contrib.sitemaps import Sitemap
+from django import forms
+
+import urllib.request
+import urllib.parse
+import urllib.error
+from django_gravatar.helpers import get_gravatar_url, has_gravatar, calculate_gravatar_hash
+from django_comments.signals import comment_was_posted
+from django_comments.models import Comment
+from django_comments.moderation import CommentModerator, moderator
+
+from taggit.managers import TaggableManager
+
+from utils.util import render_images, render_products, parse_video, markdown_to_html, extract_main_image
+
+
+def get_upload_path(self, filename):
+ return "files/%s/%s" % (datetime.datetime.today().strftime("%Y"), filename)
+
+
+class Session(models.Model):
+ title = models.CharField(max_length=200)
+ date_start = models.DateField('Start Date')
+ date_end = models.DateField('End Date')
+ slug = models.SlugField()
+ length = models.PositiveIntegerField(blank=True, null=True)
+ STATUS = (
+ (0, 'Open'),
+ (1, 'Closed'),
+ )
+ status = models.IntegerField(choices=STATUS, default=0)
+
+ class Meta:
+ ordering = ('-date_start',)
+ get_latest_by = 'date_start'
+
+ def __str__(self):
+ return self.title
+
+ def get_absolute_url(self):
+ return reverse('classes:session-detail', kwargs={"year": self.start_date.year, "month": self.start_date.strftime("%m"), "slug": self.slug})
+
+ # save length from date
+
+
+class ClassMedia(models.Model):
+ title = models.CharField(max_length=200)
+ date_created = models.DateTimeField(default=datetime.datetime.now)
+ file = models.FileField(blank=True, null=True, upload_to=get_upload_path)
+
+ def __str__(self):
+ return self.title
+
+
+class Class(models.Model):
+ title = models.CharField(max_length=200)
+ subtitle = models.CharField(max_length=200)
+ description = models.TextField()
+ requires = models.TextField('If previous classwork is required, list prerequisites here', null=True, blank=True,)
+ session = models.ForeignKey(Session, blank=True, null=True, on_delete=models.SET_NULL)
+ slug = models.SlugField()
+ uploads = models.ManyToManyField(ClassMedia, blank=True)
+ date_created = models.DateTimeField(default=datetime.datetime.now)
+ number_of_classes = models.IntegerField(blank=True, null=True)
+ CLASS_DAYS = (
+ (0, 'Mon/Wed'),
+ (1, 'Tue/Thur'),
+ )
+ class_days = models.IntegerField(choices=CLASS_DAYS, default=0)
+ price = models.FloatField()
+
+ class Meta:
+ ordering = ('-date_created',)
+ get_latest_by = 'date_created'
+
+ def __str__(self):
+ return self.title
+
+ def get_absolute_url(self):
+ return reverse('classes:detail', kwargs={"slug": self.slug})
+
+ def save(self, *args, **kwargs):
+ super(Class, self).save(*args, **kwargs)