Hi Guys,
I have a model with a bunch of choices, that are in the DB configured as below.
COL_CHOICES =(
(1, 'Not Applicable'),
(2, 'Black'),
)
COL2_CHOICES =(
(1, 'Green'),
(2, 'Blue'),
)
etc.
I want to display all these options as a menu in my templates, (to be used as a menu). Since these options are stored in the code, it does not make sense to query the DB. What would be the best way to make these available?
They should be available on all pages, Template Tags would be the way to go. However what would the template tag look like?
Update I have tried the FFQ template tag:
class OptionsNode(Node):
def __init__(self, colours, varname):
self.colours = colours
self.varname = varname
def render(self, context):
context[self.varname] = self.colours
return ''
def get_options(parser, token):
return OptionsNode(COLOUR_CHOICES, 'colour')
Update2 So the above code works, and you access the values by using colour.1 / colour.2 etc for each value respectively.
See below for full answer