Hi Everyone,
I've written a template tag that looks up an object and returns a field.
For instance:
@register.simple_tag
def content(name):
return mark_safe(Content.objects.get(name=name).content)
These tags are used to make it easier to edit content on the site. I just
need to add a {% content "about" %} to the template and modify the object
in the admin console. The above is a simple example, there are some error
messages displayed if the object is not found, but I'd like to do something
else to make it easier to see what content needs to be written by iterating
the templates to find where this tag has been used and creating the objects
needed.
My idea was to monkey patch the templatetags to create the empty objects
and then iterate over all the templates calling render_to_string() for
each. The monkey patching would look something like this:
def create_content(name):
if not Content.objects.filter(name=name).exists():
content = Content()
content.content = "Fill in %s" % name
content.save()
return ""
app.templatetags.content = create_content
Should this work? I haven't been able to get the 'create_content' function
to execute when running my initialization script. I've also tried
re-registering the tags with the same name.
Is there a better way to implement the functionality (either the editable
content or the initialization process)?
Thanks,
John
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/1cbda48e-ab4f-42b6-8f1f-e7f8435e0fa9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.