1 from django.db import models
2 from django.conf import settings
3 from django.contrib import admin
6 ('rst', 'reStructuredText'),
10 class Document(models.Model):
11 title = models.CharField(max_length=150)
12 islive = models.BooleanField()
13 folder = models.ForeignKey('Folder', null=True, blank=True)
14 format = models.CharField(max_length=10, choices=FORMAT_CHOICES)
15 slug = models.SlugField()
16 content = models.TextField()
19 return self.__unicode__()
21 def __unicode__(self):
22 return u'%s (%s)' %(self.title, self.slug)
25 super(Document, self).save()
26 # now check if we just set our selves to be live
29 otherdocs = Document.objects.filter(slug__exact=self.slug, islive__exact=True, folder__exact=self.folder).exclude(pk=self.id)
31 otherdocs = Document.objects.filter(slug__exact=self.slug, islive__exact=True, folder__isnull=True).exclude(pk=self.id)
36 def get_basic_url(self):
38 curfolder = self.folder
39 while curfolder != None:
40 folders.append(curfolder.slug)
41 curfolder = curfolder.parent
44 folderstring = "/".join(folders)
45 if folderstring != u'':
46 folderstring = "%s/" %(folderstring,)
48 return "%s%s%s/" %(settings.BPCMS_ROOT, folderstring, self.slug)
50 class Folder(models.Model):
51 title = models.CharField(max_length=150)
52 slug = models.SlugField()
53 parent = models.ForeignKey('self', null=True, blank=True)
56 return self.__unicode__()
58 def __unicode__(self):
59 return u'%s - %s' %(self.get_path(), self.title)
64 while curfolder != None:
65 folders.append(curfolder.slug)
66 curfolder = curfolder.parent
69 folderstring = "/".join(folders)
70 if folderstring != u'':
71 folderstring = "%s/" %(folderstring,)
75 def get_basic_url(self):
76 return "%s%s" %(settings.BPCMS_ROOT, self.get_path())