2011-08-22 22:04:40 +00:00
from django . db import models
from django . contrib . contenttypes . models import ContentType
class Module ( models . Model ) :
2011-09-06 02:57:15 +00:00
title = models . CharField ( max_length = 255 , help_text = " Title of Module. eg. Best Practices " )
slug = models . SlugField ( help_text = " short name of module to be used for url. eg. bestpractices " )
2011-08-22 22:04:40 +00:00
def __unicode__ ( self ) :
return self . title
def get_absolute_url ( self ) :
return " /m/ " + self . slug
class ModuleTab ( models . Model ) :
module = models . ForeignKey ( Module )
2011-09-06 02:57:15 +00:00
title = models . CharField ( max_length = 64 , help_text = " Display title for tab " )
slug = models . SlugField ( help_text = " short name for tab, to be used in url, eg. faq " )
text = models . TextField ( help_text = " text to show up in LHS for tab " )
model = models . ForeignKey ( " ModelExtra " , help_text = " Database model object tab is linked to (chose from list or ask for one to be created.) " )
is_default = models . BooleanField ( default = False , help_text = " Whether this should be the default displayed tab. " )
order = models . IntegerField ( default = 1 , help_text = " Make number higher to send it lower in order (default will always show first) " )
is_displayed = models . BooleanField ( default = True , help_text = " Uncheck to hide tab " )
2011-08-22 22:04:40 +00:00
2011-08-25 09:39:15 +00:00
class Meta :
ordering = [ ' -is_default ' , ' order ' ]
2011-08-22 22:04:40 +00:00
def __unicode__ ( self ) :
return self . title
2011-08-27 10:54:45 +00:00
def model_class ( self ) :
return self . model . model . model_class ( )
2011-08-22 22:04:40 +00:00
def get_list ( self , options ) :
2011-08-27 10:54:45 +00:00
return self . model_class ( ) . get_list ( options )
class ModelExtra ( models . Model ) :
2011-09-06 02:57:15 +00:00
model = models . ForeignKey ( ContentType , help_text = " Chose from the list of death at your own peril. " )
friendly_name = models . CharField ( max_length = 128 , help_text = " Used as display name in Admin, never to user. eg. Best Practices FAQ " )
has_comments = models . BooleanField ( default = False , help_text = " Will there be comments attached to this? " )
2011-08-27 10:54:45 +00:00
buttons = models . ManyToManyField ( ' ModelButton ' , through = ' ModelExtraButton ' , blank = True )
2011-09-06 02:57:15 +00:00
has_list = models . BooleanField ( default = True )
default_image = models . ImageField ( upload_to = ' upload/images/model_defaults/ ' , max_length = 255 , blank = True )
2011-08-27 10:54:45 +00:00
def __unicode__ ( self ) :
return self . friendly_name
class ModelSort ( models . Model ) :
model = models . ForeignKey ( ModelExtra )
2011-09-06 02:57:15 +00:00
operator = models . CharField ( max_length = 1 , help_text = " This should be either + or -. " )
field_name = models . CharField ( max_length = 64 , help_text = " Name of field on which sorting should take place, eg. title " )
friendly_name = models . CharField ( max_length = 128 , help_text = " And now, what shall we call it for the user? eg. By Title (A-Z) " )
2011-08-27 10:54:45 +00:00
def __unicode__ ( self ) :
return self . friendly_name
class ModelButton ( models . Model ) :
2011-09-06 02:57:15 +00:00
name = models . CharField ( max_length = 64 , help_text = " Name of button, eg. Download " )
icon = models . ImageField ( upload_to = ' upload/images/button_icons/ ' , blank = True , help_text = " pretty icon for the button " )
template = models . TextField ( blank = True , help_text = " you should never need to edit this field. please don ' t. " )
2011-08-27 10:54:45 +00:00
def __unicode__ ( self ) :
return self . name
class ModelExtraButton ( models . Model ) :
modelextra = models . ForeignKey ( ModelExtra )
modelbutton = models . ForeignKey ( ModelButton )
2011-09-06 02:57:15 +00:00
parameters = models . CharField ( max_length = 64 , blank = True , help_text = " if the button needs a parameter, give it here, if you dont know what this is, leave it blank. " )
2011-08-22 22:04:40 +00:00