djangosnippets.org: Latest snippets tagged with 'tags'https://djangosnippets.org/tags/tags/2012-08-31T14:24:44.364995-05:00Filter by taggit tags in the admin (Django 1.4)
2012-08-31T14:24:44.364995-05:00albertorcfhttps://djangosnippets.org/snippets/2807/<p>A <em>SimpleListFilter</em> derived class that can be used to filter by taggit tags in the admin.</p>
<p>To use, simply add this class to the <em>list_filter</em> attribute of your ModelAdmin class.</p>
<p>Ex.:</p>
<pre><code>class ItemAdmin(admin.ModelAdmin):
list_display = ('name', 'unit', 'amount')
list_filter = ('unit', TaggitListFilter)
</code></pre>
<p>Based in <a href="https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_filter">ModelAdmin.list_filter documentation</a>.</p>
Freely redistributableSASS/SCSS include template tag.
2012-02-07T14:33:36.037150-06:00bryanhelmighttps://djangosnippets.org/snippets/2678/<p>You'll need to <code>pip install pyScss</code> first.</p>
<p>Converts on the fly, so you won't want to use this for much more than just testing.</p>
<p>Usage in a template:</p>
<pre><code>{% load sass %}
{% include_sass "disclosures/css/base.scss" %}
{% include_sass "disclosures/css/grid.scss" %}
</code></pre>
Freely redistributablestrip_tags like php one
2010-04-29T09:34:43.674873-05:00hommhttps://djangosnippets.org/snippets/2002/<p>Usage:</p>
<p><code>clean_html = strip_tags(html, {'a': ['href'], 'p': ['class']})</code></p>
<p>Based on <a href="http://www.djangosnippets.org/snippets/205/">another snippet</a>.</p>
Freely redistributableFieldsets for Views
2010-01-22T10:45:48.936419-06:00Nadhttps://djangosnippets.org/snippets/1883/<p>This Snippet allows a view to controle the printed forms on the templates, in a similar way to the fieldsets used by the django admin.</p>
<p>How to Use:</p>
<p>In the view in question, put:</p>
<pre><code>def some_view(request):
...
fieldsets = (
(u'Title 1',
{'hidden' : ('field_1', 'field_2',),
'fields' : ('field_3',)}),
(u'Title …</code></pre>
Freely redistributableAdmin Apps Names Translation
2010-01-22T09:14:33.127479-06:00Nadhttps://djangosnippets.org/snippets/1882/<p>This Snippet allows for your project's apps names to be displayed as you want in the Admin, including translations.</p>
<p>The lists of apps and languages are created from your settings.py file.</p>
<p><strong>How to use</strong></p>
<p>1st part:</p>
<ul>
<li>
<p>Create a application called 'apps_verbose' in you project with the models.py and admin.py showed …</p></li></ul>
Freely redistributablePlural templatetags if quantity > 1: return single else return plural
2009-12-07T02:01:07.618626-06:00Natimhttps://djangosnippets.org/snippets/1827/<p>Regarding to a quantity, use the singular or the plural in two distincts template variables.</p>
Freely redistributableBuild tags files for emacs and vim
2009-11-19T11:30:08.377039-06:00ramenhttps://djangosnippets.org/snippets/1812/<p>Save this shell script to the root of your Django project as "tags.sh", make it executable with "chmod +x tags.sh", and run it from the project root with "./tags.sh", and you will have a "tags" file for vim and a "TAGS" file for emacs.</p>
<p>Tags will be created for Python, …</p>
Freely redistributable"Partial Templates" - an alternative to "include"
2009-01-29T17:01:30.428473-06:00vigridhttps://djangosnippets.org/snippets/1302/<p>This snippet adds simple partial support to your templates. You can pass data to the partial, and use it as you would in a regular template. It is different from Django's <code>{% include %}</code>, because it allows you to pass a custom variable (context), instead of reusing the same …</p>
Freely redistributableDaGood breadcrumbs
2009-01-19T09:37:00.763880-06:00drozzyhttps://djangosnippets.org/snippets/1289/<p>Provides two template tags to use in your HTML templates:
breadcrumb and breadcrumb_url.
The first allows creating of simple url, with the text portion and url portion. Or only unlinked text (as the last item in breadcrumb trail for example).
The second, can actually take the named url with arguments! …</p>
Freely redistributableFrequently used tags/filters for Jinja2
2008-09-17T08:48:55.547004-05:00mathwizardhttps://djangosnippets.org/snippets/1062/<p>Some frequently used filters and global functions:</p>
<p><strong>url</strong> - same as django url tag</p>
<p><strong>nbspize</strong> - replace all spaces with nbsp</p>
<p><strong>get_lang</strong> - get current language code</p>
<p><strong>timesince</strong> - converted django timesince tag</p>
<p><strong>timeuntil</strong> - converted django timeuntil tag</p>
<p><strong>truncate</strong> - tag that truncates text call it with an str …</p>
Freely redistributableTemplate Tag Caveat
2008-06-17T16:19:46.274982-05:00ericmoritzhttps://djangosnippets.org/snippets/811/<p>This describes an issue with the template system that people may come across.</p>
Freely redistributableTagging System
2008-02-07T04:04:06.279681-06:00macmichael01https://djangosnippets.org/snippets/589/<p>This is my personal tagging system that I have created. It is intended to be used for multiple applications. This tagging system also has a build in tag cloud that will generate based on the most frequently used tags that you have used or based on the number of clicks …</p>
Freely redistributable"for" template tag with support for "else" if array is empty
2008-01-15T10:04:21.178120-06:00jezdezhttps://djangosnippets.org/snippets/546/<p>This is a customized version of the default <code>for</code> template tag which takes an optional <code>{% else %}</code> clause that will be displayed if the given array is empty.</p>
<pre><code>from django.template import *
>>> t1 = Template("""
{% load mytags %}
{% for athlete in athlete_list %}
{{ athlete }} …</code></pre>
Freely redistributable"Link To" helper tag
2007-10-09T07:42:29.382335-05:00jdriscollhttps://djangosnippets.org/snippets/439/<p>Simple template tag that assumes some common conventions in order to quickly get a link to a specific model instance.</p>
Freely redistributableLoad templatetag libraries via settings
2007-07-26T11:56:19.731598-05:00miracle2khttps://djangosnippets.org/snippets/342/<p>In your settings file:</p>
<p>TEMPLATE_TAGS = (
"djutils.templatetags.sqldebug",
)</p>
<p>Make sure load_templatetags() gets called somewhere, for example in your apps <strong>init</strong>.py</p>
<p><em>Edit: Updated to work with templatetag libraries that use certain critical django-bits.</em></p>
Freely redistributable