Snippet List
This template tag provides an easy way to render objects in your template, even if you don't know ahead of time what type they are.
For example, if you've got a search page with a result list comprised of objects from various models, you can simply loop through them and render them using the tag. The tag will choose the best template and render the object for you.
The tag's docstring has all the details. I hope you find this as useful as I have. Questions, comments, complaints welcome.
- template
- tag
- model
- render
- display
This form widget allows you to just display data in a rendered form, not giving the user the opportunity to change it. The initial data will just be carried through the form and showed to the user.
In combination with snipped [1184](http://www.djangosnippets.org/snippets/1184/) you can make this even tamper safe. ;-)
- newforms
- forms
- display
- content
Template tag for displaying a list of arbitrary models. Useful for life-stream kind of pages that display blog entries, links, photos etc ordered by date. [Example](http://bjornkri.com)
**Usage:** something like:
{% for object in object_list %}
{% display_excerpt object %}
{% endfor %}
Will look for *app/model_excerpt.html* by default, and fall back on a generic *display_excerpt.html*, or returns the object's string representation as a last fallback.
*display_excerpt.html* might look something like:
<a href="{{ object.get_absolute_url }}">{{ object }}</a>
Any model you throw at it should have a *get_absolute_url* and a string representation of some sort, so this gives you the bare minimum of a title and a link to a detail page.
*display_excerpt* takes an optional argument to set the template suffix. This might be handy for generating different formatting for feeds, for instance:
{% for object in object_list %}
{% display_excerpt object "feed" %}
{% endfor %}
This will look for app/model_feed.html to render the object.
Got lots of help from mattmcc on #django for this one, thanks!
- display
- excerpt
- lifestream
This class works in compatibility with a ModelForm, but instead of show a form, it shows the field values.
The Meta class attributes can be used to customize fields to show, to be excluded, to divide by sections, to urlize text fields, etc.
**Example 1:**
class InfoSingleCertificate(ModelInfo):
class Meta:
model = SingleCertificate
sections = (
(None, ('vessel','description','document','comments','status',)),
('Issue', ('issue_date','issue_authority','issue_location',)),
)
**Example 2:**
class InfoSingleCertificate(ModelInfo):
class Meta:
model = SingleCertificate
fields = ('vessel','description','document','comments','status',
'issue_date','issue_authority','issue_location',)
**How to use:**
Just save this snippet as a file in your project, import to your views.py module (or a new module named "info.py") and create classes following seemed sytax you use for ModelForms.
- forms
- model
- display
- modelforms
- info
- values
Returns 'Morning', 'Afternoon', or 'Evening' in the local timezone (specified in settings). Required pytz. 0000-1200 considered morning, 1200-1800 considered afternoon, 1800-0000 considered evening.
- template
- tag
- templatetag
- time
- display
5 snippets posted so far.