Django community: Community blog posts RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Simple MySQL Backup @ Github
A while ago I wrote about a little script I created, for simple backups of MySQL databases and emailing the backups. I found some time to continue on the project and moved it to Github. You can find it as well as documentation there! Simple MySQL Backup @ Github -
Simple MySQL Backup @ Github
A while ago I wrote about a little script I created, for simple backups of MySQL databases and emailing the backups. I found some time to continue on the project and moved it to Github. You can find it as well as documentation there! Simple MySQL Backup @ Github -
When App Engine went wrong
About a month ago Clearwind launched a new site on App Engine. It's a pretty straightforward site for a great client we had. We'd been working on the site for many months a little bit here and there, building out new features as the client requested them. Within a few hours of starting work we had a base site running on App Engine as our test. So that site sat there, quite happily serving out those odd few requests as we added in new features. There was the occasional errors for things like data migrations and testing of new features as we went, but nothing major. And then in September, the site went live - and there was much rejoicing. And then it went down. I did an update (this is a push of the code to the server) and it came back up. And then it went down. And so on. It couldn't stay up for more than about 10 requests or so, sometimes more, sometimes less. I started tweeting, I was pretty upset. The site that had been working fine, just didn't seem to work well. We were getting errors similar to issue 772 and issue 1409. As … -
Cassandra and ElasticSearch backends for Django-nonrel in development
This is a quick update: Rob Vaterlaus has started working on a Cassandra backend and Alberto Paro is working on an ElasticSearch backend for Django-nonrel. The Cassandra backend is still experimental and lacks support for ListField (from djangotoolbox.fields), but overall it already looks very very interesting. This backend comes with experimental secondary indexes support for Cassandra and requires a recent Cassandra 0.7 build. Secondary indexes allow to efficiently query the DB by attributes other than the primary key which makes Cassandra more similar to App Engine and MongoDB than low-level key-value stores. This feature is disabled, by default, though. Currently, without secondary indexes all queries are filtered in memory. The repository contains the installation instructions, so head over and play with the code, if you're fearless. Keep in mind: it's not production ready and it depends on the latest bleeding-edge Cassandra code. Any help with the backend is highly appreciated. The ElasticSearch backend is also in alpha state. Not all unit tests pass, yet, and for now it only supports a simple subset of ElasticSearch. Basically, you can use string operations like __contains, __istartswith, __regex and you can compare integers via __gt, __lt, etc. and you can order results. Currently, … -
Postgres 9 Streaming Replication and Django-Balancer
Over the past couple of weeks I've had the opportunity to dig in to Postgres 9's streaming replication. What I found was a relatively easy way to configure a system for basic replication with very impressive speed. Postgres's streaming replication is an enhancement to the log-shipping warm standby that was available in previous versions. Instead of replaying write-ahead log (WAL) files as they become available on the slave's filesystem, the slave nodes connect directly to the master and stream the log as it generated. This results in extremely fast replication, typically under a second. It can't match the cascading features of Slony, but if you're looking for a simple structure with a master database feeding one or more read-only slaves then Postgres 9 is a great choice. Here's how I got everything working on Ubuntu 10.04. UPDATE: I've changed the NFS details below to squash the user and group IDs and set the anonymous access user and group to the slave server's user and group IDs. This resolves issues where the postgres use has a different ID on the slave server than the master server, so files received from master are owned by the wrong user. Postgres 9 Postgres 9 … -
OCLUG Web Site to Become a Wiki
The Ottawa Canada Linux Users Group board of directors has decided to retire their Django meeting announcement web site and replace it with a plain wiki. But, it's been a great run for close to 4 years: 69 meetings posted, always up-to-date 65 speakers 34 local Linux jobs posted hundreds of members' blog posts aggregated zero maintenance time (removal of old meetings & jobs is automatic) zero reported defects zero down time -
Keeping your logging compatible with Sentry
Something I've noticed while digging around in various libraries, is the inconsistent use of logging. This creates some problems with Sentry, and in the end gives us some very ugly exception logging. Let's take a simple example (we're going to use Celery for this one): if task.eta: try: ... -
Keeping your logging compatible with Sentry
Something I've noticed while digging around in various libraries, is the inconsistent use of logging. This creates some problems with Sentry, and in the end gives us some very ugly exception logging. Let's take a simple example (we're going to use Celery for this one): if task.eta: try: ... -
Peter Norvig on programming languages
Peter Norvig: [Programming] language choice is not as important as all the other choices: if you have the right overall architecture, the right team of programmers, the right development process that allows for rapid development with continuous improvement, then many languages will work for you; if you don’t have those things you’re in trouble regardless of your language choice. -
Capturing images from a webcam in Django with jpegcam
Django integration of jpegcam widget that allow users to save images from a computer webcam. -
Django template filter para obtener thumbnails de youtube.
Acá les dejo un Django template filter para obtener el thumbnail de un video de youtube a partir de su url, ejemplo de uso: <img src="{{video.url|youthumbnail: 's'}}"/> Tiene dos parámetros de tamaño ‘s’ para un thumbnail pequeño y ‘l’ para … Continue reading → -
Django template filter para obtener thumbnails de youtube.
Acá les dejo un Django template filter para obtener el thumbnail de un video de youtube a partir de su url, ejemplo de uso: <img src="{{video.url|youthumbnail: 's'}}"/> Tiene dos parámetros de tamaño 's' para un thumbnail pequeño y 'l' para un thumbnail grande. Ver en DjangoSnippets -
Local Django development with Nginx
When doing local Django development with runserver you end up doing some changes, then refreshing in Firefox/Chrome/Safari again and again. Doing this means that all your static resources are probably served via Django. Presumably via django.views.static.serve, right? What's wrong with that? Not much, but we can do better. So, you serve it via Nginx and let Nginx take care of all static resources. You'll still use Django's own runserver so no need for mod_wsgi, gunicorn or uWSGI. This requires that you have Nginx installed and running on your local development environment. First you need to decide on a fake domain name. For example mylittlepony. Edit your /etc/hosts file by adding this line: 127.0.1.1 mylittlepony [410 more words] -
Local Django development with Nginx
When doing local Django development with runserver you end up doing some changes, then refreshing in Firefox/Chrome/Safari again and again. Doing this means that all your static resources are probably served via Django. Presumably via django.views.static.serve, right? What's wrong with that? Not much, but we can do better. So, you serve it via Nginx and let Nginx take care of all static resources. You'll still use Django's own runserver so no need for mod_wsgi, gunicorn or uWSGI. This requires that you have Nginx installed and running on your local development environment. First you need to decide on a fake domain name. For example mylittlepony. Edit your /etc/hosts file by adding this line: 127.0.1.1 mylittlepony [410 more words] -
Local Django development with Nginx
When doing local Django development with runserver you end up doing some changes, then refreshing in Firefox/Chrome/Safari again and again. Doing this means that all your static resources are probably served via Django. Presumably via django.views.static.serve, right? What's wrong with that? Not much, but we can do better. So, you serve it via Nginx and let Nginx take care of all static resources. You'll still use Django's own runserver so no need for mod_wsgi, gunicorn or uWSGI. This requires that you have Nginx installed and running on your local development environment. First you need to decide on a fake domain name. For example mylittlepony. Edit your /etc/hosts file by adding this line: 127.0.1.1 mylittlepony [410 more words] -
Local Django development with Nginx
When doing local Django development with runserver you end up doing some changes, then refreshing in Firefox/Chrome/Safari again and again. Doing this means that all your static resources are probably served via Django. Presumably via django.views.static.serve, right? What's wrong with that? Not much, but we can do better. So, you serve it via Nginx and let Nginx take care of all static resources. You'll still use Django's own runserver so no need for mod_wsgi, gunicorn or uWSGI. This requires that you have Nginx installed and running on your local development environment. First you need to decide on a fake domain name. For example mylittlepony. Edit your /etc/hosts file by adding this line: 127.0.1.1 mylittlepony [410 more words] -
Django Patterns: Model Inheritance
This post discusses the two flavors of model inheritance supported by Django, some of their use-cases as well as some potential gotchas. -
Django Patterns: Model Inheritance
This post discusses the two flavors of model inheritance supported by Django, some of their use-cases as well as some potential gotchas. Overview When the queryset refactor landed a couple years ago, Django's ORM grew support for model inheritance. Model inheritance comes in two flavors, abstract and ... not. What are the important differences in how Django handles these two types of inheritance? Multi-table inheritance (not abstract) Directly extending a model results in two tables where the shared fields are stored in one table (the parent model's table) and the fields unique to the child model are stored on the child model's table. The child model contains a foreign key to the parent model and whenever queried automatically includes the joins. class Media(models.Model): title = models.CharField(max_length=255) pub_date = models.DateTimeField() class Photo(Media): # note that Photo extends Media image = models.ImageField(upload_to='photos') class Video(Media): video = models.FileField(upload_to='videos') class VideoWithThumbnail(Video, Photo): """ Querying this object will result in 3 inner joins on filters/gets Saving/deleting will require at least 4 queries, but in my testing saving actually required 10 queries and deleting 13! """ pass Because of the way these items are stored in the database, it is possible to query against all media … -
Django Patterns: Model Inheritance
This post discusses the two flavors of model inheritance supported by Django, some of their use-cases as well as some potential gotchas. Overview When the queryset refactor landed a couple years ago, Django's ORM grew support for model inheritance. Model inheritance comes in two flavors, abstract and ... not. What are the important differences in how Django handles these two types of inheritance? Multi-table inheritance (not abstract) Directly extending a model results in two tables where the shared fields are stored in one table (the parent model's table) and the fields unique to the child model are stored on the child model's table. The child model contains a foreign key to the parent model and whenever queried automatically includes the joins. class Media(models.Model): title = models.CharField(max_length=255) pub_date = models.DateTimeField() class Photo(Media): # note that Photo extends Media image = models.ImageField(upload_to='photos') class Video(Media): video = models.FileField(upload_to='videos') class VideoWithThumbnail(Video, Photo): """ Querying this object will result in 3 inner joins on filters/gets Saving/deleting will require at least 4 queries, but in my testing saving actually required 10 queries and deleting 13! """ pass Because of the way these items are stored in the database, it is possible to query against all media … -
Django Patterns: Model Inheritance
This post discusses the two flavors of model inheritance supported by Django, some of their use-cases as well as some potential gotchas. Overview When the queryset refactor landed a couple years ago, Django's ORM grew support for model inheritance. Model inheritance comes in two flavors, abstract and ... not. What are the important differences in how Django handles these two types of inheritance? Multi-table inheritance (not abstract) Directly extending a model results in two tables where the shared fields are stored in one table (the parent model's table) and the fields unique to the child model are stored on the child model's table. The child model contains a foreign key to the parent model and whenever queried automatically includes the joins. class Media(models.Model): title = models.CharField(max_length=255) pub_date = models.DateTimeField() class Photo(Media): # note that Photo extends Media image = models.ImageField(upload_to='photos') class Video(Media): video = models.FileField(upload_to='videos') class VideoWithThumbnail(Video, Photo): """ Querying this object will result in 3 inner joins on filters/gets Saving/deleting will require at least 4 queries, but in my testing saving actually required 10 queries and deleting 13! """ pass Because of the way these items are stored in the database, it is possible to query against all media … -
Django Patterns: Model Inheritance
This post discusses the two flavors of model inheritance supported by Django, some of their use-cases as well as some potential gotchas. Overview When the queryset refactor landed a couple years ago, Django's ORM grew support for model inheritance. Model inheritance comes in two flavors, abstract and ... not. What are the important differences in how Django handles these two types of inheritance? Multi-table inheritance (not abstract) Directly extending a model results in two tables where the shared fields are stored in one table (the parent model's table) and the fields unique to the child model are stored on the child model's table. The child model contains a foreign key to the parent model and whenever queried automatically includes the joins. class Media(models.Model): title = models.CharField(max_length=255) pub_date = models.DateTimeField() class Photo(Media): # note that Photo extends Media image = models.ImageField(upload_to='photos') class Video(Media): video = models.FileField(upload_to='videos') class VideoWithThumbnail(Video, Photo): """ Querying this object will result in 3 inner joins on filters/gets Saving/deleting will require at least 4 queries, but in my testing saving actually required 10 queries and deleting 13! """ pass Because of the way these items are stored in the database, it is possible to query against all media … -
Django static media always returning 404 not found
I spent too long tonight figuring out a weird problem. On a dev server, I was using django.views.static.serve to serve media files. But it was returning 404 (not found) for any file. The requests for media files weren’t even showing up in Django’s built-in server’s output. That had me baffled until I dug deep enough in Django’s code to figure it out. The ADMIN_MEDIA_PREFIX was the same as MEDIA_URL. That was it. Django’s built-in server doesn’t log requests for admin media, so that’s why there was no log output. The built-in server also handles admin media separately, so when I tried to request a media file, it intercepted and looked for it in the admin media. The solution is for the ADMIN_MEDIA_PREFIX to be different from MEDIA_URL, e.g. /media/ and /media/admin/. -
JOINs via denormalization for NoSQL coders, Part 3: Ensuring consistency
In part 1 and part 2 we introduced the concept of denormalization, materialized views and background tasks in order to emulate JOINs in the to-one direction on NoSQL databases. Now we'll talk about all remaining little but important snippets of the puzzle left over and discuss how to ensure that this method works in real world situation like server crashes. When to start background tasks? Let's first remember our current situation: We have a materialized view (i.e. the model PhotoUserView) containing denormalized properties of users (i.e. gender) and denormalized properties of photos (i.e. popularity). This materialized view is used to emulate JOINs in the to-one direction. Instances of PhotoUserView have to be kept up to date. If a user edits properties of a photo we have to start a background task in order to update all denormalized fields of the corresponding PhotoUserView entity If a user changes his/her gender (or her hair color) we have to start background tasks in order to update the denormalized gender of all PhotoUserView entities which point to that specific user Given this we have to answer when to start background tasks while keeping in mind that the connection / database / web server can … -
Django Admin Customization Examples
I've worked on a couple of projects recently that required some customization of the Django admin. One of the things that I love about Django's built-in admin is that it is created with a very extensible class-based structure. Here are some of the ways I was able to customize the admin to add functionality. Adding Buttons to the Change View One of the major features needed for a project was the ability to manage a workflow for a model. The model progressed through different status stages, and the admin team needed to be able to make decisions based on that current status. To handle this, I added some new buttons to the model's change view, and used my ModelAdmin and ModelForm subclasses to move the model around in the workflow accordingly. Customizing the Template In order to differentiate the workflow management options from the standard Admin delete & save buttons, I added a row of buttons directly above the standard delete & save row. I created a file in my templates directory with the path admin/myapp/mymodel/change_form.html that looked something like this: {% extends "admin/change_form.html" %} {% block after_related_objects %} {% if original.pk %} <div class="submit-row"> <p class="deletelink-box">Manage this request</p> {% … -
Testing GEODjango applications with Django 1.2
Today I lost 3 hours of my time trying to test a GeoDjango app. It all happened because I incorrectly created the gis template, by default expected to be called template_postgis Since Django 1.2 you don’t need to do anything special for testing GeoDjango apps. You used to need to set up the variable TEST_RUNNER. Don’t do this anymore! So I was happily executing: python manage.py test myapp and I was getting: Creating test database 'default'... Got an error creating the test database: ERROR: permission denied to copy database “template_postgis” Type 'yes' if you would like to try deleting the test database 'test_myapp', or 'no' to cancel: If you use Spanish you would get: Got an error creating the test database: se ha denegado el permiso para copiar la base de datos «template_postgis» I finally found how to fix this issue. The problem is that when I created template_postgis I didn’t set it to be a template. You can check it doing: SELECT * FROM pg_database; You can fix it doing: update pg_database set datistemplate=true where datname='template_postgis'; Finally this is how you should create your template_postgis for the first time: #!/usr/bin/env bash POSTGIS_SQL_PATH=`pg_config --sharedir`/contrib/postgis-1.5 # Creating the template spatial database. …