A subclassed version of the standard Django Paginator (django.core.paginator.Paginator) that automatically caches pages as they are requested. Very useful if your object list is expensive to compute.
MIT licensed.
This is an override the save method of our Photo model. This new save method essentially takes the image, thumbnails it into our various sets of dimensions (for … in self.IMAGE_SIZES…), and save each one (into its own ImageField) before finally call the overwritten method to save the original image.
Yes, the dimensions are hardcoded, and there is currently not a way to regenerate them in different sizes, but one shouldn't be that hard to come up with, because you just could just load each photo object to regenerate, then save it again (or something along those lines).
mattpdx helped a lot with figuring out this code.
A Textarea widget which appends basic Textile formating instructions in the same way Basecamp's Writboard product displays some basic helper markup alongside the edit area.
Most of the time when I need to iterate over Whatever.objects.all() in a shell script, my machine promptly reminds me that sometimes even 4GB isn't enough memory to prevent swapping like a mad man, and bringing my laptop to a crawl. I've written 10 bazillion versions of this code. Never again.
**Caveats**
Note that you'll want to order the queryset, as ordering is not guaranteed by the database and you might end up iterating over some items twice, and some not at all. Also, if your database is being written to in between the time you start and finish your script, you might miss some items or process them twice.
I updated [MarkdownTextField](http://www.djangosnippets.org/snippets/882/) to have some choices in markup. It currently support for Markdown, Textile, Plain Text, and Plain HTML. It will add `%s_html` for the complied HTML and `%s_markup_choices` for a drop down of markup choices.
Usage:
class MyModel(models.Model):
description = MarkupTextField()
This script generates an [GraphViz](http://www.graphviz.org/) graph of your database structure from your django models.
See the usage if the file underneath the license.
Works exactly like the standard "extends" tag but enables one to fallback on a default template. This tag is LIMITED, as it falls back to the next template with the same name that DOES NOT contain "extends_default" (does NOT simulate full inheritance, just a single level).
A partial solution to problems like http://jeffcroft.com/blog/2008/aug/05/default-templates-django/.
MIT licensed.
This is the (revamped) bash script I use to keep my git branches up-to-date with SVN to make my life a lot easier, just save it in a text file and read the instructions at the top!
Hope it's useful to somebody else than me ;)
Just a quick hack for a Controller style pattern. Similar to the approach taken in django.contrib.admin views
things this breaks:
1. {% url %} and reverse()
2. validation provided by regex urlpatterns
Django's serializer has some limitations which makes it a bit of a pain to use. Basically it will ignore any atributes that have been added to a model object.
The code below is for an alternative serializer. This version allows you select what attributes will be serialized on a per object basis. It also allows you to either serialize the data into json or xml.
The original json encoder was written by [Wolfram Kriesing](http://wolfram.kriesing.de/blog/)
Example Usage:
dumper = DataDumper()
dumper.selectObjectFields('class_name',[...fields...])
dumper.selectObjectFields('class_name',[...fields...])
dumper.dump(model_instance,'xml')
dumper.dump(model_instance,'json')
dumper.dump(queryset,'xml')
This is a very small, simple piece of code, but essential for using fields of type 'money' on MS SQL Server, through FreeTDS. This took me quite some time to hunt down, as get_placeholder() is in fact an undocumented feature.
**Example:**
class MyModel(models.Model):
price = MoneyField()
I think this method is handy, since you don't need to remember if you
need urlquote or urlencode. It does both and adds a question mark
between the path and the get parameters, if later are present.
And it works around a bug in Django: MultiValueDicts (request.GET, request.POST) are handled correctly.
Related: [http://code.djangoproject.com/ticket/9089](http://code.djangoproject.com/ticket/9089)