from django.db import models from django.dispatch import dispatcher from django.db.models import signals from django.contrib.auth.models import User, AnonymousUser from bn_django.photos.models import Photo class SubJournal(models.Model): name = models.CharField("full title", blank=False,max_length=196) date = models.DateField("date started", auto_now_add=True) slug = models.SlugField() description = models.TextField("description of content",blank=True) class Meta: get_latest_by = 'date' ordering = ['-date'] class JournalCommon(models.Model): author = User("User who created this") date = models.DateTimeField("associated day", auto_now=True) last_edited = models.DateField("day last edited", auto_now_add=True) subjournal = models.ForeignKey(SubJournal,blank=True,null=True) defunct = models.BooleanField("is this entry all around done with?",default=False,blank=False) private = models.BooleanField("is this entry for validated users only?",default=False,blank=False) class Meta: abstract = True get_latest_by = 'date' ordering = ['-date'] class Entry(JournalCommon): html_content = models.TextField("html format content", blank=False) title = models.CharField("entry title", max_length=384) slug = models.SlugField() def get_absolute_url(self): return "/journal/%s/"%self.slug class MicroEntry(JournalCommon): html_content = models.TextField("html format content", blank=False) text_content = models.TextField("text version of content", blank=True,null=True) class Artifact(JournalCommon): html_caption = models.TextField("html format caption", blank=False) text_caption = models.TextField("text format caption", blank=True,null=True) entry = models.ForeignKey(Entry, blank=True) title = models.CharField("title of the artifact", max_length=256, blank=True) class Meta: abstract = True class VideoArtifact(Artifact): codec = models.CharField("what codec/format the video is", max_length=384) filepath = models.FileField(upload_to="artifacts/%Y/%m/") external_url = models.URLField("external representation to reduce bandwidth (youtube, etc)", blank=True) class CodeArtifact(Artifact): code = models.TextField("raw source code", blank=False) language = models.CharField("what programming language", max_length=160, \ blank=True) class LinkArtifact(Artifact): url = models.URLField("external link to something wonderful!", blank=True) class ImageArtifact(Artifact,Photo): """Multiply inherets from the photo app """ pass def build_display_images(sender, instance, signal, *args, **kwargs): """Simple hook for save-after trigger """ instance.build_display_images() def delete_thumbnails(sender, instance, signal, *args, **kwargs): """Simple hook for pre-delete trigger. """ instance.delete_thumbnails() signals.post_save.connect(build_display_images, sender=ImageArtifact) signals.pre_delete.connect(delete_thumbnails, sender=ImageArtifact) from django.contrib import admin admin.site.register(Entry) admin.site.register(MicroEntry) admin.site.register(SubJournal) admin.site.register(Artifact) admin.site.register(LinkArtifact) admin.site.register(CodeArtifact) admin.site.register(VideoArtifact) admin.site.register(ImageArtifact)