djangosnippets.org: Latest snippets posted by asfaltboyhttps://djangosnippets.org/users/asfaltboy/2015-09-03T09:16:55.105197-05:00asfaltboyFilter 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 redistributableTemplate tag to render collections.Counter as an html table
2015-06-19T10:12:27.396198-05:00asfaltboyhttps://djangosnippets.org/snippets/10502/<p>Render a given instance of collections.Counter into a 2 column html table.</p>
<p>Optionally accepts <code>column_title</code> keyword argument which sets the table
key column header.</p>
<p>Usage:</p>
<pre><code>{% counter_table event_counter column_title='event type' %}
</code></pre>
<p>The above will render the a table from the <code>event_counter</code> variable with the first (key) column set to "event …</p>
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 redistributableQSerializer with default to JSON input and output
2013-11-09T00:46:49.626188-06:00asfaltboyhttps://djangosnippets.org/snippets/3003/<p>A module to serializers/deserializes Django Q (query) object</p>
Freely redistributable