Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
More good words for z3
Electric Duncan some more good things to say about zope3 or z3 here, this time it's vs django. To a certain extent I do agree with some of the things mentioned in that article. At times I do feel that I am trying to bend django to my will when I was coding my application, but alas, I am too green in z3 to give any meaningful comment regarding the comparison. Here, duncan mentions something that piqued my interest - Coding his application in z3, with learning curve thrown in took him two days ! Now that is a wow-ser for me ! Although at the back of my mind the article look more slanted towards zope than django which might explain why the author felt more at home with z3, but then it's a good read after all and has inspired me more to go towards giving z3 another serious look for my web development work. -
Announcing StaticGenerator for Django
Want to speed up your Django app? StaticGenerator is a Python class for Django that makes it easy to create static files for lightning fast performance. It accepts strings (URL), Models (class or instance), Managers, and QuerySets in a simple syntax. -
Cool Django Apps / Frameworks / Add-Ons
Ran across three really cool looking extensions to django: databrowseDatabrowse is a Django application that lets you browse your data. As the Django admin dynamically creates an admin interface by introspecting your models, Databrowse dynamically creates a rich, browsable Web site by introspecting your models. sitemap Django comes with a high-level sitemap-generating framework that makes creating sitemap XML files easy. webdesign The django.contrib.webdesign package, part of the “django.contrib” add-ons, provides various Django helpers that are particularly useful to Web designers (as opposed to developers). I am anxious to given these items a spin, especially databrowse. -
Cool Django Apps / Frameworks / Add-Ons
Ran across three really cool looking extensions to django: databrowseDatabrowse is a Django application that lets you browse your data. As the Django admin dynamically creates an admin interface by introspecting your models, Databrowse dynamically creates a rich, browsable Web site by introspecting your models. sitemap Django comes with a high-level sitemap-generating framework that makes creating sitemap XML files easy. webdesign The django.contrib.webdesign package, part of the “django.contrib” add-ons, provides various Django helpers that are particularly useful to Web designers (as opposed to developers). I am anxious to given these items a spin, especially databrowse. -
Django Fixtures and Flatpage Deployment
I was introduced today to the concept and django feature known as Fixtures, while reading my dead-tree version of the new django book. I am currently building a small site, fairly simple and mostly static. I have written an app that is my own take on the flatpages that are in django.contrib (a post on this later) -- I basically needed a little more flexibility for different islands of content. In building this site and setting up the appropriate flatpages in my development, I realized that I am going to need to seed the database when I release to production or else there are going to be a lot of 404 errors. Also, since the pages are referred to in my menus, I need for the url on the flatpage model to be exact. It's not that many pages, but still, I thought, there had to be a better way that either manually hand entering all the data, troubleshooting 404s for typos in the url field, or doing any manual exporting of data at the mysql prompt. As if by some divine revelation, I happened across the chapter in the book talking about django-admin dumpdata/loaddata. What's cool about this is … -
Django Fixtures and Flatpage Deployment
I was introduced today to the concept and django feature known as Fixtures, while reading my dead-tree version of the new django book. I am currently building a small site, fairly simple and mostly static. I have written an app that is my own take on the flatpages that are in django.contrib (a post on this later) -- I basically needed a little more flexibility for different islands of content. In building this site and setting up the appropriate flatpages in my development, I realized that I am going to need to seed the database when I release to production or else there are going to be a lot of 404 errors. Also, since the pages are referred to in my menus, I need for the url on the flatpage model to be exact. It's not that many pages, but still, I thought, there had to be a better way that either manually hand entering all the data, troubleshooting 404s for typos in the url field, or doing any manual exporting of data at the mysql prompt. As if by some divine revelation, I happened across the chapter in the book talking about django-admin dumpdata/loaddata. What's cool about this is … -
getting to pesky foreign key data in django
Optimizing databases is a good practice and should be done for any enterprise applications, but as all things go there is a price to pay. The price you pay is when calling back and displaying the data into one can be real PITA. django is a damn good framework and allows you to do work fast with a pedal-to-the-metal feel but then certain amounts of work still has to be done when you have foreign keys defined.Say you have a database with two tables : contacts and address. The relationship of the two tables are of the one to many kind, I could never really wrap my head around the one-many many-one many-many thingy so let me just say it in layman so I understand it better myself. "One contact can have one or more than one address"class Contacts(models.Model):..... bla blaclass Address(models.Model): customer_id=models.ForeignKey(Contacts,edit_inline=models.STACKED,num_in_admin=2)So in the code above you have basically linked both the tables together using a ForeignKey relationship. the 'edit_inline' ... mumbo jumbo just tells django to add the address field into the main Contacts form during creation and modification and not as a pop up link ( This is important and could be a clincher for normal users … -
Filtering foreign key choices in newforms-admin
I decided it was time to learn something about the newforms-admin branch of Django, so I set out to try to write a couple of simple models for administering a mail server (something we always needed at GMTA, but I have never really liked any of the currently available options). Here is the models so far: class Customer(models.Model): name = models.CharField(max_length=100) slug = models.SlugField() def __str__(self): return self.name class UserProfile(models.Model): user = models.ForeignKey(User, unique=True) customer = models.ForeignKey(Customer) class Domain(models.Model): name = models.CharField(max_length=100) customer = models.ForeignKey(Customer) def __str__(self): return self.name def save(self): # When a user adds a Domain, save the current customer. if not self.id: self.customer = get_current_user().customer_set.all()[0] # Call the super save method super(Domain, self).save() class Mailbox(models.Model): name = models.CharField(max_length=100) domain = models.ForeignKey(Domain) password = models.CharField(max_length=100) def __str__(self): return '%s@%s' % (self.name, self.domain) class Meta: verbose_name_plural = "mailboxes" class Alias(models.Model): name = models.CharField(max_length=100) domain = models.ForeignKey(Domain) destination = models.EmailField() def __str__(self): return '%s@%s -> %s' % (self.name, self.domain, self.destination) class Meta: verbose_name_plural = "aliases" Model notes There is a few gotchas in the above model code: Remember to add AUTH_PROFILE_MODULE to your settings. See the Django Book on user profiles for details. I use a thread locals hack to … -
Configure Mercury mail transport system for external mail
Usually I develope my projects locally on my pc. Needless to say that you sometimes have to send an email from your script to external mail to check if everything is fine. So you need to configure your system in a way that your local apache webserver is able to send mail to external addresses. I always use XAMPP for Windows because it contains everything you need for developing PHP applications as well as all the stuff for sending mails: fake sendmail und Mercury Mail Transport System. I reference to XAMPP 1.6.5 (for Windows) and Mercury 4.5 here. Mercury is already pre-configured in XAMPP - all settings that I don't explicitly address stay as they are :) I'm writing this because I'm not a mail professional and read a lot of tutorials and none of them really worked. So I extracted what I needed and put it all together. An important assumption for this tutorial is that you have your own SMTP server, for example the one that your webspace hoster provides. So let's get started: start Mercury (using the XAMPP Controlpanel) and then open the admin panel. first of all we disable the HTTP server of Mercury so that … -
Configure Mercury mail transport system for external mail
Usually I develope my projects locally on my pc. Needless to say that you sometimes have to send an email from your script to external mail to check if everything is fine. So you need to configure your system in a way that your local apache webserver is able to send mail to external addresses. I always use XAMPP for Windows because it contains everything you need for developing PHP applications as well as all the stuff for sending mails: fake sendmail und Mercury Mail Transport System. I reference to XAMPP 1.6.5 (for Windows) and Mercury 4.5 here. Mercury is already pre-configured in XAMPP - all settings that I don't explicitly address stay as they are :) I'm writing this because I'm not a mail professional and read a lot of tutorials and none of them really worked. So I extracted what I needed and put it all together. An important assumption for this tutorial is that you have your own SMTP server, for example the one that your webspace hoster provides. So let's get started: start Mercury (using the XAMPP Controlpanel) and then open the admin panel. first of all we disable the HTTP server of Mercury so that … -
Configure Mercury mail transport system for external mail
Usually I develope my projects locally on my pc. Needless to say that you sometimes have to send an email from your script to external mail to check if everything is fine. So you need to configure your system in a way that your local apache webserver is able to send mail to external addresses. I always use XAMPP for Windows because it contains everything you need for developing PHP applications as well as all the stuff for sending mails: fake sendmail und Mercury Mail Transport System. I reference to XAMPP 1.6.5 (for Windows) and Mercury 4.5 here. Mercury is already pre-configured in XAMPP - all settings that I don't explicitly address stay as they are :) I'm writing this because I'm not a mail professional and read a lot of tutorials and none of them really worked. So I extracted what I needed and put it all together. An important assumption for this tutorial is that you have your own SMTP server, for example the one that your webspace hoster provides. So let's get started: start Mercury (using the XAMPP Controlpanel) and then open the admin panel. first of all we disable the HTTP server of Mercury so that … -
Comment Notification in Django
After receiving a number of spam comments on my blog, I decided to utilize Django's built-in signal dispatch system to notify me via email when I receive a comment. Code included. -
Django ModelForm and newforms
Browsing the Django code after a recent svn up shows that newforms.form_for_instance and friends are deprecated and that you should use a ModelForm instead. This post gives a brief example of how to do this. -
Django generic AJAX form validation
I just created a generic view for Django which allows a developer to easily add AJAX-style form validation to a newforms based form. The system needs one server-side view, and some client-side JavaScript. You can find the view code in my Django snippets Git repository. The view only works with POST requests. It takes a standard HttpRequest and some options: form_class: this parameter defines the newforms class to validate against. It can be specified in the extra args parameter of the view’s urlconf. If you don’t specify it, the ‘form_class’ POST field will be used. If this doesn’t exist either, an exception is raised. The parameter can be a newforms form instance, a string, or a class (which should be a subclass of BaseForm). format: the serialization format to use. Currently only ‘json’ is supported. args: extra argument list to provide to the form constructor (shouldn’t be provided in most cases) kwargs: extra argument dics to provide to the form constructor (shouldn’t be provided in most cases) Next to the server-side view you’ll need some pretty basic JavaScript code on client side. I use JQuery and the JQuery Form plugin. Here’s some sample code, assuming the form ID is ‘my_form’, … -
Best tech bits of 2007
Número uno: Duels.com Launched in Q4, Duels is a seriously addictive online fantasy dueling game where players collect items to kit out their characters and challenge each other to a battle shadow fight style. I came across it via TechCrunch and now can't stop signing in for a sly duel or 10. The beauty of it is the asynchronous game play, which means I challenge a bunch of players and then come back in an hour or two to check the results or respond to any challenges issued to me. Perfect. Do yourself (and me) a favour and sign up using this link. You'll have the satisfaction of knowing you're helping me earn a nifty service badge - just don't blame me when you lose a week of your life! Nummer twee: Twitter (and twitterific) Ah twitter! Strictly speaking twitter belongs in 2006, but I can't help but include it here. Part chat, part mircoblog, part txt, twitter is a communication platform that informs the future. Or something. Someone far smarter that me will soon come up with a killer app to push the platform, but until then, it's an integral part of my day. I've met quite a few … -
Filesystem issues and django-couchdb work
Last night, when shutting down my laptop (which had been up for quite a long time because of suspend/resume niceness), it crashed. I don’t know what exactly happened: pressed the GNOME’s logout button, applications were closed, until only my background was visible, then the system locked up, so I suspect my X server (some part of it, GPU driver (fglrx) might be the bad guy). I was able to sysrq s u o, so I thought everything would be relatively fine. This morning I powered on my system, and while booting, fsck of some partitions was taking a rather long time. It’s pretty normal fsck was taking somewhat longer, but not thát long… I’m using JFS on most logical volumes. When the consistency check of my /home partition was done, a whole load of invalid files was displayed and later on moved to lost+found: 34068 files. Once booted, I scanned my filesystems again, rebooted, logged in, started X. Everything started fine, until I launched Evolution: it presented my the ‘initial run’ wizard. Other issues (on first sight): all Firefox cookies were gone, and Pidgin’s blist.xml was corrupted. When using my old computer (which had frequent lockups on heavy IO usage) … -
CouchDB with Python
Today I’ve been investigating CouchDB a little better (only heard some rumors about it before). It’s actually a pretty nice technology which can, in some places, be pretty useful… I tend to compare it to caching serialized PHP associative arrays or Python dict’s in a Memcached server using some specific prefixes, except it’s not really memory-based (it’s persistent), you get a complete query interface (views), there’s dataset versioning support (!), etc. While writing this I start to wonder what similarities I ever saw between CouchDB and a Python pickled dict in Memcached… Anyway, one use case I saw was site user profiles: profile data is most of the time not relational at all, so why store it in a relational database, which makes it sometimes rather hard to add extra profile information fields, unless you use some dirty ‘save serialized form’ trick, which renders your data unqueryable? Storing profile information (using eg. a user’s primary email address or login name as key for the user profile document) in CouchDB allows you to extend the profile “schema” easily: just add a field to your profile editting form, make sure it’s processed server-side an stored in the profile document, and add some … -
Django domain redirect middleware
Most web developers know it’s possible to serve one site on several domains or subdomains, using eg. the ServerAlias Apache directive. Sometimes this behaviour is not wanted: you want your main domain to be “foo.tld”, although “www.foo.tld” should work too, and maybe even some completely different domains. This way it’s possible to have permalinks, and you won’t get bad points from search engine spiders who don’t like the same content to be available on several URIs. In Django there’s the PREPEND_WWW setting, which will force all requests to be redirected to www.foo.bar when coming in on foo.bar, etc. This functionality is rather limited though. As I wanted to be able to have one unique main domain in my new application, I wrote a middleware which accomplishes this in a very generic way, using the django.contrib.sites framework. You need to add this middleware before all others in your settings file, even before the CommonMiddleware. Here’s the code: from django.contrib.sites.models import Site from django.http import HttpResponsePermanentRedirect from django.core.urlresolvers import resolve from django.core import urlresolvers from django.utils.http import urlquote class DomainRedirectMiddleware(object): def process_request(self, request): host = request.get_host() site = Site.objects.get_current() if host == site.domain: return None # Only redirect if the request is … -
Two Django snippets
Last 2-3 days I’ve been working on this new site project. As (almost) all web projects I started last 2 years, I’m using the Django framework to develop the site, as I just love it for several reasons. Tonight I’d like to share 2 snippets. The first one is one I use quite regularly. It’s a replacement for django.shortcuts.render_to_response, which requires one to always add a RequestContent keyword argument to be able to access MEDIA_URL etc in templates. This replacement (which I mostly put in utils/shortcuts.py) is completely API-compatible with the default render_to_response implementation, but if you pass it a request object as first parameter (and no context_instance), it automaticly uses a RequestContext. from django.shortcuts import render_to_response as real_render_to_response from django.http import HttpRequest from django.template.context import RequestContext def render_to_response(*args, **kwargs): # Check old API if len(args) > 0 and not isinstance(args[0], HttpRequest): return real_render_to_response(*args, **kwargs) if not kwargs.get('context_instance', None): kwargs['context_instance'] = RequestContext(args[0]) return real_render_to_response(*args[1:], **kwargs) The second one is an custom form which can be used with the django-contact-form application. It automaticly uses the name and email address of the user if logged in, otherwise provides the standard text input fields. It might be a good example of how to … -
Using Django’s FormPreview with @login_required
As part of Django’s ‘batteries included’ philosophy, it comes with the FormPreview class to make it easy to automate this workflow: “Display an HTML form, force a preview, then do something with the submission.” Also provided is the @login_required decorator which makes it easy and obvious to mark functions as requiring a logged-in user. Both [...] -
Picture gallery using MooTools
After dealing with Windows Vista some time ago there was this idea about creating an image gallery for the web that looks like the tab view in vista using the aero user interface. First you could think about creating this with flash but it's also possible with javascript and the mootools framework. It took a long time until it worked properly for putting it into the web, mainly because there was rarely time working on it. I created an extra page for the script that answers to the name of "ImageFlip" because I'll continue working on it. If you have any questions, ask me here or write an email as specified on the page: to the ImageFlip minpage.... -
Picture gallery using MooTools
After dealing with Windows Vista some time ago there was this idea about creating an image gallery for the web that looks like the tab view in vista using the aero user interface. First you could think about creating this with flash but it's also possible with javascript and the mootools framework. It took a long time until it worked properly for putting it into the web, mainly because there was rarely time working on it. I created an extra page for the script that answers to the name of "ImageFlip" because I'll continue working on it. If you have any questions, ask me here or write an email as specified on the page: to the ImageFlip minpage.... -
Picture gallery using MooTools
After dealing with Windows Vista some time ago there was this idea about creating an image gallery for the web that looks like the tab view in vista using the aero user interface. First you could think about creating this with flash but it's also possible with javascript and the mootools framework. It took a long time until it worked properly for putting it into the web, mainly because there was rarely time working on it. I created an extra page for the script that answers to the name of "ImageFlip" because I'll continue working on it. If you have any questions, ask me here or write an email as specified on the page: to the ImageFlip minpage.... -
2008 Digital Edge Award Finalists
The 2008 DIgital Edge Award finalists were just announced, and I’m excited to see several World Company sites and projects on there as well as a couple of sites running Ellington and even the absolutely awesome Django-powered PolitiFact.com. At work we don’t do what we do for awards. We do it to serve our readers, tell a story, get information out there, and do it as best we can. At the same time even being nominated as finalists is quite an honor, and evokes warm fuzzy feelings in this programmer. Here are the various World Company projects and sites that were nominated (in the less than 75,000 circulation category): Most Innovative Multimedia Storytelling: 24 Hours in Lawrence (LJWorld.com) Best Local Guide or Entertainment Site: Lawrence.com Best Design and Site Architecture: LJWorld.com Best Overall News Site: LJWorld.com Not too shabby for a little media company in Kansas. I’m particularly excited about the LJWorld.com nominations since it hasn’t been too long since we re-designed and re-launched the site with a lot of new functionality. Scanning the finalists I also see a couple of other sites running Ellington as well as several special projects by those sites. As someone who writes software for … -
Django Template Tag for Dictionary Access
About a million times when writing Django pages I’ve been iterating through a list of objects and wanted to look up a value in a dictionary keyed by object.id. But you can’t, the built-in tags don’t allow it. The standard workaround is to loop over the list and zip the hash data into some kind [...]