Snippet List
ModelChoiceTitleField is a ModelChoiceField descendent that creates <OPTIONS> with title elements based on the field specified in title_source_field:
priority=ModelChoiceTitleField(Priority.objects.all(),
initial=Priority.objects.get(default=True).id,
title_source_field='long_description')
That will generate a `<SELECT>` element looking like:
<select name="priority" id="id_priority">
<option value="1" title="Some extremely important task.">Emergency</option>
...
</select>
In the `<option>` above, the title was retrieved from the `long_description` field for the instance of the Priority class. The word Emergency came from a call to the instance of the Priority class' `__unicode__()` method. The value of the option is the PK for the instance of the Priority class.
A {% mailto %}{% endmailto %} template tag that requires an e-mail destination and optionally accepts subject, cc and bcc. It will then wrap whatever is within the tag in an `<a href="mailto:..."> </a>` HTML tag.
See the docstring in the code for the {% mailto %} usage and some examples.
You will need to load this template tag to your template. You can find detailed instructions [here](http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#code-layout). But in a nutshell:
1. Create a templatetags package (meaning a directory with a __init__.py file in it) on the same level as your application's model.py
2. Put the code for this tag in a module (example: extra_tags.py)
3. On your template use {% load extra_tags %} -- note: the app where the templatetags package was created needs to be in INSTALLED_APPS
4. Use {% mailto user.email 'You subject here for {{user.get_full_name}}' %}blah{% endmailto %}
This is my first django template tag. I am also NOT tremendously experienced with Python. Criticism and corrections are more than welcome.
- template
- tag
- templatetag
- email
- mailto
celopes has posted 2 snippets.