Skip to content

Instantly share code, notes, and snippets.

@jonrohan
Created April 7, 2011 22:10
Show Gist options
  • Save jonrohan/908874 to your computer and use it in GitHub Desktop.
Save jonrohan/908874 to your computer and use it in GitHub Desktop.
from django.contrib.auth.models import Group
from django.core.urlresolvers import reverse
from django.db import models
from django.utils.translation import ugettext_lazy as _
'''
The Docs site will have heirarchy like follows:
Topic
| -- Article
| -- Section
| -- Section
| -- Article
| -- Section
| -- Section
'''
class Topic(models.Model):
"""Topic model docstring"""
# Title of the topic ie. Getting Started, Client Code, Tutorials
title = models.CharField(max_length=200)
# If we want to sort the topics in another way
sort = models.IntegerField(default=0)
slug = models.SlugField(max_length=200)
groups = models.ManyToManyField(Group, blank=True)
def articles(self):
return Article.objects.filter(topic=self).order_by('sort')
def __unicode__(self):
return self.title
class Article(models.Model):
"""Article model docstring"""
# Title of the article.
title = models.CharField(max_length=200)
# For article sorting
sort = models.IntegerField(default=0)
# The topic bucket to put this article in
topic = models.ForeignKey('Topic')
slug = models.SlugField(max_length=200)
groups = models.ManyToManyField(Group, blank=True)
def get_absolute_url(self):
return reverse("docs-article", kwargs={"topic_slug": self.topic.slug,"article_slug":self.slug})
def sections(self):
return Section.objects.filter(article=self).order_by('sort')
def __unicode__(self):
return self.title
class Section(models.Model):
"""Section model docstring"""
title = models.CharField(max_length=200)
article = models.ForeignKey('Article')
content = models.TextField()
sort = models.IntegerField(default=0)
slug = models.SlugField(max_length=200)
groups = models.ManyToManyField(Group, blank=True)
def __unicode__(self):
return self.title
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment