Django: less (magic) is more
Today I updated my Django play/development environment to the new magic-removal branch, and migrated my proto-wiki as an exercise. Following the RemovingTheMagic instructions on the official Django wiki made it fairly easy. (I added some notes on dealing with custom template tags.)
This branch is about more than cleaning up some of the needlessly clever bits found in earlier implementations; it also has some really nice syntax refinements. Compare this:
reporters.get_list(fname__exact='John', order_by=('lname',))
to this:
Reporter.objects.filter(fname='John').order_by('lname')
No contest. I’m loving these refinements so much I almost don’t want to get to 1.0!
Update: I did a count of the actual lines of Python in my little wiki project, not including settings.py and urls.py. Fifty-two – and that’s with the addition of a “delete” function, which I didn’t have before.
The updated proto-wiki source is now available.
Luke commented on Mon Feb 13 04:34:04 2006:
The new syntax is rather nice. Have you discovered things like this:
(Reporter.objects.filter(fname='John') | Reporter.objects.filter(fname='Fred'))
? It does what you expect, and does it lazily (a single DB query). Sweet.
Andrew commented on Mon Feb 13 10:59:43 2006:
As someone who is going to take another look at django because of this removing the magic, have you released the updated source to proto-wiki?
Paul commented on Mon Feb 13 11:56:08 2006:
Andrew: I have now!
Luke: I hadn’t seen that, thanks. A little verbose, but I definitely prefer it to the old double-underscore-delimited magic. Clearly I have some reading to catch up on.
Eric Moritz commented on Mon Feb 27 11:00:05 2006:
This stuff is nice… I’m not looking forward to rewriting all my code though…
Tim commented on Fri Dec 29 05:37:16 2006:
Thanks for sharing the code, I live the simplicity of Django/Python driven websites!
keith commented :
i have downloaded you code but i keep getting an error about the WIKI_SITEBASE what is this and where do i get it?