djangosnippets.org: Latest snippets tagged with 'range'https://djangosnippets.org/tags/range/2015-09-03T09:16:55.105197-05:00Filter 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 redistributableMultiRangeField and MultiRangeFormField
2014-06-01T12:14:28.673304-05:00bobtikihttps://djangosnippets.org/snippets/3070/<p><strong>Designed to hold a list of pages and page ranges for a book/magazine index.</strong></p>
<p>A custom model field (and accompanying form field) that saves comma-separated pages and page ranges in human-readable string form. Includes some clean-up code, so that you can add a new page or range at the end …</p>
Freely redistributablemkrange - create a range() inside a template
2010-02-14T16:27:59.517376-06:00woleverhttps://djangosnippets.org/snippets/1926/<pre><code>Accepts the same arguments as the 'range' builtin and creates
a list containing the result of 'range'.
Syntax:
{% mkrange [start,] stop[, step] as context_name %}
For example:
{% mkrange 5 10 2 as some_range %}
{% for i in some_range %}
{{ i }}: Something I want to repeat\n …</code></pre>
Freely redistributableTemplate range loop
2010-01-28T14:24:16.924850-06:00nfghttps://djangosnippets.org/snippets/1899/<p>This tag is meant to mimic the python use of range in a for-loop: 'for i in range(start, end, step)'. It is implemented like a loop and it takes both variable names from the context and constant integers as arguments.</p>
<pre><code>Syntax:
{% range end as i %}
{{ i }} …</code></pre>
Freely redistributableFormat date range
2009-03-30T10:38:30.940747-05:00bmihelachttps://djangosnippets.org/snippets/1405/<p>templatetags/date_range.py</p>
Freely redistributableTemplate range filter
2009-03-09T09:22:10.377746-05:00zalunhttps://djangosnippets.org/snippets/1357/<p>Easy to use range filter.
Just in case you have to use a "clean" for loop in the template.</p>
<p>Inspired by <a href="http://www.djangosnippets.org/snippets/779/">Template range tag</a></p>
<p>Copy the file to your templatetags and load them.</p>
<p><a href="http://docs.djangoproject.com/en/dev/howto/custom-template-tags/">Django doc | Custom template tags and filters</a></p>
Freely redistributableRangeField and RangeWidget
2008-10-02T07:47:47.936226-05:00marinhohttps://djangosnippets.org/snippets/1104/<p>These field and widget are util for to those fields where you can put a star and end values.</p>
<p>It supports most of field types and widgets (tested with IntegerField, CharField and DateField / TextInput and a customized DateInput).</p>
<p><strong>Example of use:</strong></p>
<pre><code>class FormSearch(forms.Form):
q = forms.CharField(max_length=50, label=_('Search for'))
price_range …</code></pre>
Freely redistributableTemplate range tag
2008-06-01T09:26:53.537546-05:00newmaniesehttps://djangosnippets.org/snippets/779/<p>This is a simple tag that I am sure has been written before, but it helps people with the problem, 'how do I iterate through a number in the tempaltes?'.</p>
<p>Takes a number and iterates and returns a range (list) that can be
iterated through in templates</p>
<pre><code>Syntax:
{% num_range …</code></pre>
Freely redistributableTime ranges like 7-9 p.m.
2008-01-17T13:53:34.819848-06:00sgbhttps://djangosnippets.org/snippets/551/<p>Template filter to format a start and end time in to a range. Uses Django's <a href="http://www.djangoproject.com/documentation/templates/#now">"P" format</a> and assumes start and end time are on the same day or night before/morning after. </p>
<p><code>{{ start_time|time_range:end_time }}</code></p>
<p>Examples:</p>
<p>7-8 p.m.</p>
<p>8 p.m. - midnight</p>
<p>noon - 4 p.m.</p>
<p>9:45 a.m. - 5:15 …</p>
Freely redistributable