At work I was asked to add content to the main satchmo page
(index.html) that could later be customized through the admin. I am
posting my solution in case anyone is interested (this is assuming you
have the directory structure that clonesatchmo.py creates): in
localsite.models add:
from django.db import models
class static_content(models.Model):
name = models.CharField(max_length=25, unique=True)
title = models.TextField(blank=True)
content = models.TextField(blank=True)
in localsite.admin add this code:
from store.localsite.models import static_content
admin.site.register(static_content)
Now run syncdb. Go into your admin and you should now see a localsite
header with a section static_contents. Click on static_contents, in
the upper right click add static_content. For name give it a short,
unique name we will use this later. Add a title and content as you
see fit. In title and content feel free to include html. Save the
objects, and remember what you put for page for later.
create a localsite/templatetags directory, put an empty __init__.py in
it. Make a file called static_content.py with the contents:
ffrom django import template
from django.template.defaultfilters import stringfilter
from store.localsite.models import static_content
register = template.Library()
@register.filter(name='get_static_content')
@stringfilter
def get_static_content(value):
try:
return list(static_content.objects.filter(name=value))[0]
except:
return None
now in you index.html template (of course you have copied it over to
your local templates folder) add this to the top where other
templatetags are laoded (you could also do this in any other
template):
{% load static_content %}
wherever you want your content (for example you could replace {% trans
"Welcome to the shop." %}) put this:
{% with "put name here"|get_static_content as static %}
{{ static.title|safe }}
{{ static.content|safe }}
{% endwith %}
of course replace put name here with the name you gave in the admin.
Adding the |safe filter tells django not to escape characters so it
will let anything through. I did this so I could include html but in
some cases it might not be the best idea. Also, you can add anything
you want to the models, more fields, less fields, whatever. The
template tag just returns a list object (in this case it only has
name, title, content, but it will have anything in the models). I
didn't combine name and title because you may want to change the title
and this way you can and you dont have to change what
get_static_content is searching against.
I think thats right if anyone has problems post back
Enjoy
-Josh
--
You received this message because you are subscribed to the Google Groups
"Satchmo users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/satchmo-users?hl=en.