djangosnippets.org: Latest snippets tagged with 'filter'https://djangosnippets.org/tags/filter/2018-06-26T01:52:47.488552-05:00Filter to shorten Natural Time
2018-06-26T01:52:47.488552-05:00abhiramrhttps://djangosnippets.org/snippets/10649/<ul>
<li>This is a filter to shorten the natural time value obtained using naturaltime function from humanize.</li>
</ul>
Freely redistributableSoft hyphenation filters
2017-10-19T02:45:52.598478-05:00Xowaphttps://djangosnippets.org/snippets/10628/<p>Automatically hyphenate raw text or HTML code</p>
Freely redistributableaggregate filter
2017-01-25T05:46:42.720745-06:00atombrellahttps://djangosnippets.org/snippets/10603/<p>Makes it possible to add a filtering condition directly after the aggregate function (or possible, <code>aggregate(expression) WITHIN GROUP (ordering clause)</code>. This is mostly useful if the annotation has two or more expressions, so it's possible to compare the result with and without the applied filter; it's more compact than …</p>
Freely redistributableAvaliabilityAtDateListFilter
2016-08-27T19:05:16.815045-05:00m_aciekhttps://djangosnippets.org/snippets/10583/<p>If your model have two dates, start and end of something, you may want to have filter which allow you to show objects which last on specific day.</p>
Freely redistributabledjango admin filter for GenericForeignKey field
2016-04-21T04:27:32.027802-05:00dkoldyaevhttps://djangosnippets.org/snippets/10564/<p>Simple filter for django ModelAdmin</p>
<p>How use:</p>
<pre><code>#models.py
class ObjectWithGenericForeignKey(model.Model):
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object= GenericForeignKey('content_type', 'object_id', for_concrete_model=False)
#admin.py
class CommentAdmin(admin.ModelAdmin):
list_filter = (get_generic_foreign_key_filter(u'Filter title'),)
</code></pre>
Freely redistributableFilter changelist by a numeric field using a number of common value ranges
2015-09-03T09:16:55.105197-05:00asfaltboyhttps://djangosnippets.org/snippets/10527/<h2>How to use</h2>
<p>Use this <a href="https://docs.djangoproject.com/en/1.8/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_filter">admin filter</a> together with a numeric field to allow filtering changlist by field
values range (in this case, age groups):</p>
<p>For example, to group customers by age groups:</p>
<pre><code>class Customer(models.Model):
# ...
age = models.IntegerField()
age.list_lookup_range = (
(None, _('All')),
([0, 2], '0-2'),
([2, 4], …</code></pre>
Freely redistributableDjango filter for shrinking [big] numbers
2015-08-04T02:07:20.194108-05:00pedromagnushttps://djangosnippets.org/snippets/10520/<p>Simple filter that shrinks [big] numbers sufixing "M" for numbers bigger than million, or "K" for numbers bigger than thousand.
It does a division over the number before converting to string so rounding is properly done.</p>
<p>Examples:</p>
<p><code>{{ 123456|shrink_num }} >> 123.6K</code></p>
<p><code>{{ 1234567|shrink_num }} >> 1.2M</code></p>
Freely redistributableDatetime adjuster for Django Templates
2015-07-22T08:54:23.899048-05:00McAnixhttps://djangosnippets.org/snippets/10516/<p>The filter is <strong>specific to datetime objects</strong> and no allowance has been made to convert strings or epoch times. Also <strong>no type checking</strong> is performed so misuse will result in an error.</p>
<p>To use include the above snippet in a file called templatetags/customfilters.py or append to existing filters file then …</p>
Freely redistributabletweetparser filter
2015-06-28T08:02:32.094796-05:00VincentLoyhttps://djangosnippets.org/snippets/10504/<p>Django Template Filter that parse a tweet in plain text and turn it with working Urls</p>
<p>Ceck it on <a href="https://github.com/VincentLoy/tweetparser-django-template-filter">GitHub</a></p>
<h1>tweetParser Django Template Filter</h1>
<p>this is a port of <a href="https://github.com/VincentLoy/tweetParser.js">tweetParser.js</a> to work as a Django template filter</p>
<h2>How does it work ?</h2>
<p>Once installed, just :
<code><p>{{ your_tweet|tweetparser }}</p></code></p>
<h2>Installation …</h2>
Freely redistributableContentType template filter
2013-12-31T02:30:37.563758-06:00asfaltboyhttps://djangosnippets.org/snippets/3015/<p>Custom template filter to retrieve a content type of a given model instance. Useful for ModelForms which want to set the content_type field (i.e: GenericForeignKey).</p>
<h3>A usage example:</h3>
<pre><code>{% load helpers %}
{% with instance|content_type as ctype %}
<input type="hidden" name="content_type" value="{{ ctype.pk }}">
{% endwith %}
</code></pre>
<p>Original idea from …</p>
Freely redistributablePassword Obfuscation Log Filter
2013-06-28T17:08:04.046722-05:00nikmolnarhttps://djangosnippets.org/snippets/2966/<p>This is a simple logging <a href="https://docs.djangoproject.com/en/1.5/topics/logging/#topic-logging-parts-filters">filter</a> to ensure that user-entered passwords aren't recorded in the log or emailed to admins as part of the request data if an error occurs during registration/login.</p>
Freely redistributableMake Proper Nouns Posessive
2013-06-05T13:22:39.846461-05:00skarphacehttps://djangosnippets.org/snippets/2926/<p>A template filter to make proper nouns posessive. If <code>context_var</code> was 'skarphace':</p>
<pre><code>{{ context_var|s }}
</code></pre>
<p>Would be:</p>
<pre><code>skarphace's
</code></pre>
Freely redistributableDjango Admin Filter __in query string
2013-04-23T20:11:52.220970-05:00justhamadehttps://djangosnippets.org/snippets/2914/<p>A hack to add <strong>in ability to links generated in the Django Admin Filter which will add and remove values instead of only allowing to filter a single value per field. Example ?age_group</strong>in=under25%2C25-35</p>
Freely redistributableKeeping filter states after edits (Django 1.4)
2012-11-20T18:44:37.724802-06:00rhfunghttps://djangosnippets.org/snippets/2849/<p>When saving an edit to an object from a filtered list view you are, by default, returned to list view without any of your filters applied.</p>
<p>This solves that problem, keeping the filtered view in a session variable until you reach a point where the session key is deleted.</p>
<p>This …</p>
Freely redistributableAction that respects the filters in changeview_list
2012-10-11T01:52:32.427674-05:00grillermohttps://djangosnippets.org/snippets/2832/<p>With this function if you filter using regular admin filters you'll reduce the queryset to the objects in view.</p>
Freely redistributable