Source

django-pim / projects / models.py

Full commit
from django.db import models
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic

class Note(models.Model):
    title = models.CharField(max_length=80)
    slug = models.SlugField()
    created_on = models.DateField(auto_now_add=True)
    content_type = models.ForeignKey(ContentType)
    object_id = models.PositiveIntegerField()
    content_object = generic.GenericForeignKey()
    description = models.TextField()
    def __unicode__(self):
        return u"%s" % self.title
    @models.permalink
    def get_absolute_url(self):
        if self.content_type.model == 'project':
            return ('projects-view-note', [self.content_object.slug, self.slug])
        elif self.content_type.model == 'goal':
            return ('projects-view-goal-note', [self.content_object.project.slug, self.content_object.slug, self.slug])

class Project(models.Model):
    title = models.CharField(max_length=80)
    slug = models.SlugField()
    active = models.BooleanField()
    complete = models.BooleanField()
    created_on = models.DateField(auto_now_add=True)
    description = models.TextField()
    notes = generic.GenericRelation(Note)
    def __unicode__(self):
        return u"%s" % self.title
    @models.permalink
    def get_absolute_url(self):
        return ('projects-view', [self.slug])

class Goal(models.Model):
    title = models.CharField(max_length=80)
    slug = models.SlugField()
    project = models.ForeignKey(Project)
    complete = models.BooleanField()
    created_on = models.DateField(auto_now_add=True)
    due_on = models.DateField(blank=True, null=True)
    completed_on = models.DateField(blank=True, null=True)
    description = models.TextField()
    notes = generic.GenericRelation(Note)
    def __unicode__(self):
        return u"%s" % self.title
    @models.permalink
    def get_absolute_url(self):
        return ('projects-view-goal', [self.project.slug, self.slug])