it/itf/bestpractices/models.py

77 lines
2.2 KiB
Python
Raw Normal View History

2010-12-06 22:34:49 +00:00
from django.db import models
from tagging.fields import TagField
2011-01-04 06:27:10 +00:00
from django.core.paginator import Paginator, InvalidPage, EmptyPage
from app.models import ItfModel
2010-12-06 22:34:49 +00:00
2011-01-04 06:27:10 +00:00
class BestPractice(ItfModel):
2010-12-06 22:34:49 +00:00
title = models.CharField(max_length=512)
story = models.TextField()
guideline = models.TextField(blank=True)
law = models.TextField(blank=True)
theatre = models.TextField(blank=True, help_text="Spotlight on Theatre text")
2010-12-07 14:51:24 +00:00
quick_howto = models.TextField(blank=True)
2010-12-06 22:34:49 +00:00
tags = TagField(blank=True, help_text="Enter as many tags as you like, separated by commas.")
2010-12-07 14:51:24 +00:00
category = models.ForeignKey("BestPracticeCategory")
2011-01-11 20:32:18 +00:00
added = models.DateTimeField(auto_now_add=True, null=True)
modified = models.DateTimeField(auto_now=True, null=True)
2011-01-04 06:27:10 +00:00
fts_fields = ['title', 'story', 'guideline', 'law', 'theatre', 'quick_howto']
fk_filters = ['category']
sort_fields = ['title']
2010-12-06 22:34:49 +00:00
def __unicode__(self):
return self.title
2010-12-07 14:51:24 +00:00
2011-01-04 06:27:10 +00:00
def info_dict(self):
return {
'title': self.title,
'story': self.story,
'guideline': self.guideline,
'law': self.law,
'theatre': self.theatre,
'quick_howto': self.quick_howto,
'category': self.category.name,
'category_id': self.category.id
}
def list_dict(self):
return {
'id': self.id,
'title': self.title,
'category': self.category.name,
}
2011-01-11 14:26:36 +00:00
def preview_dict(self):
return {
'id': self.id,
'title': self.title,
'category': self.category.name,
'quick_howto': self.quick_howto,
'guideline': self.guideline
}
2011-01-04 06:27:10 +00:00
2010-12-07 14:51:24 +00:00
class BestPracticeCategory(models.Model):
name = models.CharField(max_length=256)
description = models.TextField(blank=True)
def __unicode__(self):
return self.name
class BestPracticeLink(models.Model):
url = models.URLField()
text = models.TextField(blank=True)
bestpractice = models.ForeignKey(BestPractice)
def __unicode__(self):
return self.url
class BestPracticeImage(models.Model):
image = models.ImageField(upload_to='upload/images/bestpractices/')
caption = models.CharField(max_length=512, blank=True)
bestpractice = models.ForeignKey(BestPractice)
def __unicode__(self):
return self.caption