My Django model has a field within which I want to have reference logic. As an example:
This is an example of text in the field.[ref type="quotation" name="Martin" date="2010"]
When presented in the final markup, this is rendered as (reduced example):
This is an example of text in the field.<a href="#ref">1</a>
[SNIP]
<ul>
<li><a name="ref1">Martin, 2010</a></li>
</ul>
So, essentially, I am building a list of references to go into a different {{}} block further down the page.
Should this kind of text-processing logic be in the view (so I pass 2 values to the template, 1 that is the modified text and 1 that is the reference table), or is there some more Django-esque way to do it via filters etc.?
If you’re actually storing the references in the text field like, this, then essentially you’re using a simple markup language to store the references.
In which case, I think the template would be the place to do this.
Unfortunately, I don’t know of any way to have a filter create and write to a context variable. So instead of using a filter, you’re going to have to use a tag, something like:
BTW: if there is a way to write to the page context while using a filter, I’d love to know about it.
Update
To implement it, you’d use something like: