djangosnippets.org: Latest snippets posted by itavorhttps://djangosnippets.org/users/itavor/2011-12-15T23:11:31.033810-06:00itavorAdmin actions as buttons instead of a menu [v2]
2011-12-15T23:11:31.033810-06:00itavorhttps://djangosnippets.org/snippets/2630/<p>Add this to your admin change_list.html template to replace the actions drop-down with buttons.</p>
<p>This is a rewritten version of snippet <a href="http://djangosnippets.org/snippets/1931/">1931</a> with Django 1.3 compatibility and cleaner code. Thanks to <a href="http://djangosnippets.org/users/andybak/">andybak</a> for the idea.</p>
Freely redistributableCustom managers with chainable filters
2008-01-23T09:47:41.500546-06:00itavorhttps://djangosnippets.org/snippets/562/<p>The Django docs show us how to give models a custom manager. Unfortunately, filter methods defined this way cannot be chained to each other or to standard queryset filters. Try it:</p>
<pre><code>class NewsManager(models.Manager):
def live(self):
return self.filter(state='published')
def interesting(self):
return self.filter(interesting=True)
>>> NewsManager().live().interesting()
AttributeError: '_QuerySet' object has no attribute 'interesting' …</code></pre>
Freely redistributable