djangosnippets.org: Latest snippets tagged with 'iterable'https://djangosnippets.org/tags/iterable/2012-03-04T21:13:14.749258-06:00Template filter to get each attribute value in an iterable
2012-03-04T21:13:14.749258-06:00strangefeatureshttps://djangosnippets.org/snippets/2706/<p>Iterate through the supplied iterable and return the <code>attrname</code> eattribute
of each element in the iterable. Useful with the <code>join</code> filter</p>
Freely redistributableshuffle templatetag
2011-02-25T09:59:08.176364-06:00deanmalmgrenhttps://djangosnippets.org/snippets/2370/<p>This is useful for randomizing an iterable of objects in place in a django template. Usage:
</p>
<pre><code>{% load shuffle %}
{# now some_list is ordered #}
{% shuffle some_list %}
{# now some_list is randomized #}
</code></pre>
Freely redistributableMultiple querysets
2010-02-20T14:11:02.419194-06:00t_rybikhttps://djangosnippets.org/snippets/1933/<p>This is an upgrade of snippet <a href="http://www.djangosnippets.org/snippets/1103/">1103</a>.</p>
<p>Exemplary usage:</p>
<pre><code>class Blog(models.Model):
name = models.CharField(max_length=100)
def __unicode__(self):
return self.name
class Post(models.Model):
title = models.CharField(max_length=50)
blog = models.ForeignKey(Blog)
def __unicode__(self):
return self.title
class Meta:
abstract=True
class Article(Post):
text = models.TextField()
class Link(Post):
url = models.URLField()
blog = Blog(name="Exemplary blog")
blog.save()
Article(title="#1", …</code></pre>
Freely redistributableChunks template filter
2008-10-03T06:10:44.058539-05:00oggyhttps://djangosnippets.org/snippets/1106/<p>A simple filter which divides an iterable (list, tupe, string, etc) in chunks, which can then be iterated over separately. A sample of the filter usage is given: a gallery template in which I needed to display images in a table, three images per row, one row for images followed …</p>
Freely redistributable