Archive for the ‘Django’ Category

Django Tree Libraries 0

django-mptt

Nested Set trees.
A register() call is used to set things up; it ads the necessary fields to the model.
A tree model still has a foreign key to itself. This is the API you use to manage the tree. Signals are used that the hidden tree fields are updated when the parent ForeignKey changes. No add_child() [...]

Django: Flexible date form fields accepting (almost) any input 1

At critify, we do a lot of copy & paste. Sometimes, that means copy & pasting a date from another site into a Django DateTimeField on our site. This can be tedious, because Django only supports a fixed number of strict input formats, while the actual input can at times be something quite freeform. So [...]

Properly sending contact form emails and how to do it in Django 0

Ever since I decided to use SpamStopsHere (their excellent, by the way) I noticed that some emails sent to me by one of my site's contact form didn't pass their SPF check.
It turns out that apart from your normal "From" sender, an email message also has an envelope sender specified in the Return-Path header. The [...]

quick update: django-assets now supporting Jinja 2 0

Since I've been playing a round with Jinja a bit the last few days, I needed django-assets to support it as well. So it can now be used with both Django and Jinja templates, even simultaneously. So far, the code is only in bzr, not packaged up. Details in the Readme, though it's all pretty [...]

Django: Testing with twill 0

After putting it off again and again, I decided that it would be finally time to make an effort and start writing some actual tests for my views (rather than just the code behind them). Beyond Django's neat, but somewhat limited test client, the tool to do this seems to be twill.
Twill supports a WSGI intercept [...]

Making a copy of a model instance 0

Copying a model instance, i.e. creating a new database row based on an existing one (copying all the data except the primary key), doesn't seem to be a very common need - it's not directly supported by the Django ORM, and Google doesn't turn much up, either.
But maybe that's because, in most cases, it really [...]

django-xappy: Searching with Xapian 0

Yes, yet another search app. However, unlike other projects, say this year's GSoC project, it doesn't try to be generic. Rather, it is specific to Xapian, making it possible to make full use of all the advanced features the excellent Xappy library offers. Xappy is a high-level interface to Xapian (as opposed to the [...]

django-tables: A QuerySet renderer 15

While trying to add a simple sorting feature to the critify game listing, I went off on a strange train of thought involving a bunch of future functionality I only have a very vague picture of, and decided that it would be best to choose the most complex approach possible and create a separate, overarchitected [...]

django-assets 2

There are already a couple asset management addons for Django out there, and so I feel somewhat bad for coming up with another one.
In my defense, non of the other approaches appealed to me: django-yslow apparently simply searches recursively through the project directory, finding media files and merging them into one single package. django-assetpacker has [...]

Django: Finding the current project's path 1

Problem: You need the filesystem location of the current project, but your code doesn't know which project is is used by (think 3rd party app).
Answer:  Define "project location" as "location of settings file", and you can do:

from django.conf import settings
os.path.dirname(os.path.normpath(os.sys.modules[settings.SETTINGS_MODULE].__file__))