Here is what I tried - is working.  Not sure if it's as clever as it
could be, but it works.

# models.py

class GlobalOptions(models.Model):
    key = models.SlugField(max_length=30,unique=True)
    value = models.TextField()

# views.py

def global_options():
    dict = {}
    for go in GlobalOptions.objects.all():
        dict[go.key] = go.value
    return dict

def my_view(request, template_name):
    # ...
    return render_to_response('template.html', { 'global':
global_options() })

# template.html

<p>key_name =  {{ global.key_name }}</p>

I can add additional keys, as needed, and just have to reference them
in the template (don't have to change any of the python).

Thoughts ?

Damon

On Jul 5, 9:12 am, thornomad <damont...@gmail.com> wrote:
> Hi Daniel -
>
> Okay ... so, it looks like I could do this two ways (maybe more).
> After reading:http://docs.djangoproject.com/en/dev/ref/templates/api/
>
> 1. I could create my own context process and define it in
> TEMPLATE_CONTEXT_PROCESSORS -
>
> 2. (maybe more straightforward) I could create a function in a view
> that returns a dictionary of all the items (value/key pairs) in a
> particular Model ... then pass that to the view when it gets process.
> Then I could add/remove value/key pairs form the admin as needed.
>
> I think I may try out option 2, and see how it goes.  Sounds easier,
> anyway.
>
> Thanks!  I will report back when/if I get it working.
>
> Damon
>
> On Jul 4, 11:36 pm, dvainsencher <dvainsenc...@gmail.com> wrote:
>
> > On Jul 4, 9:27 am, Damon Timm <damont...@gmail.com> wrote:
>
> > > Hello everyone -
>
> > > I wondered if anyone had insight on a Model for site-wide "global"
> > > options.  I am thinking of a place to store: site title, site meta,
> > > site description, specific global links (twitter, facebook, etc),
> > > support contact email, etc ... The model itself doesn't seem too
> > > complicated, maybe:
>
> > > class GlobalOptions(models.Model):
> > >     opiton = models.SlugField('Machine Readable Option
> > > Name',max_length=50,unique=True)
> > >     value = models.TextField('Option Value')
> > >     # more fields could be included, of course (date_created, 
> > > description, blah)
>
> > > My question, though, is about how to easily get these new "options"
> > > into a template tag.  So that I could simply do:
>
> > > {{ globaloptions.optionname }}
>
> > > And it would return the value for that option or, if the option didn't
> > > exist, it would return nothing.  I have been looking around for a way
> > > to do this and coming up blank -- I am new to both Python and Django,
> > > so I'm sure the answer is there, I just don't know where/how to look
> > > for it.
>
> > > Any insight would be great!
>
> > > Damon
>
> > You can set a globaloptions dictionary in the response context with
> > option attribute as key and value attribute as value.
>
> > []s
> > daniel
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to