Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Using Django as a Pass Through Image Proxy
An earlier post shows you how to setup Nginx as a pass through image proxy. This post shows you how to do it with just Django and nothing else. The Problem We've solving the same problem as the earlier post. However, I will repeat it here for clarity as there's been some confusion. You have a production DB with lots of images uploaded by users. For example, NationalGeographic.com has over 11gb of user uploaded images. When you download a data dump of the production database, it has links to all these images which you don't have. You either have to download and sync all the images locally every time you copy the database, live with broken images or point your static images to the prod server. Copying images locally is the brute force method and will work. If you have all day to sync up images. Pointing to the images in prod also works, but if you upload your own images to test functionality... You will not be able to see those new images. You have a prod site with gigabytes and gigabytes of user generated static content. Whenever the database from production is copied to some lesser environment, like … -
Writing a custom field in Django
Reusable code is one of the most talked-about silver bullets in our toolkit. Django has a huge ecosystem of reusable apps, but not nearly so many reusable fields. Apps and fields generally solve different problems, though, and while an app can be retemplated or modified to fit your use case, a field is often times so specialized or exact in its purpose that either you need it or you don't. In this entry I'll discuss a great use-case for a field we had at work building out live March Madness coverage, and a popular field that is also an app. -
1950s
Mine is Johnny Depp, unchallenged. But I’m not into celebrities very much. Download 1950s movies -
What’s New in django-formfieldset 1.1
I have just released 1.1 version of django-formfieldset. I has been almost a year since version 1.0. Here is a summary of changes for this version: New Example Project There is a new and improved example project. It is designed to be some sort of documentation at the same time. When you run the example [...] -
Largest open-source Django project
Thierry Schellenbach from YouTellMe.nl recently wrote on his blog that their site is probably the largest Django project in terms of codebase. Since their project isn’t open-source, it’s hard to tell if that claim is true or not. But it got me wondering. What is the largest open-source Django-based project around? Some times ago I already posted some ‘source lines of code’ (SLoCs) metrics about the Peach³ Django project (41209 at the time). But is SLoCs the best way to define which project is the largest? Or maybe we should use some more ‘Django-based’ metrics, like number of unique apps (22 for Peach³) or number of models (86)? Or maybe the largest project is the project with the most people using it on a day-to-day basis (approximately 350 for Peach³ at the moment). And, using any of these metrics, what would be the largest Django-based open-source project around at the moment? I could not find any metrics of any other projects. I feel Peach³ might actually be one of the bigger projects out there, but I have nothing to base that feeling on. -
Tagging overhaul and some downtime
We experienced a half-hour of downtime just a little bit ago while rolling out an overhaul to our tagging system. While downtime is never fun, it means that we've fixed some lingering issues with our tagging system. Our original tagging system had some problems handling tags with spaces and that should be fixed now. For the geeks in the house, this means that we've moved away from django-tagging and to django-taggit. If you see anything out of order, please let us know by sending a quick note using the feedback box at the bottom of every page. -
Rails and Django commands : comparison and conversion
The most commonly used Rails commands and their Django equivalents Rails Django rails console manage.py shell rails server manage.py runserver rake None rails generate None rails dbconsole manage.py dbshell rails app_name django-admin.py startproject/manage.py startapp rake db:create manage.py syncdb The salient points to note are, Django has all commands via manage.py, Rails has it broken into [...] Related posts:Django for a Rails Developer The Rails and Django models layer Rosseta stone -
Django based startup – YouTellMe.nl
YouTellMe.nl is a completely Django based startup located in Amsterdam. We’re probably one of the largest Django projects in terms of codebase. Pretty soon the famous nextweb awards are coming up. (remember those guys which broke into Michael Arrington’s house?). And we need some love from the Django community. Lots of it. Pretty please nominate youtellme.nl for the next web! http://dsa.thenextweb.com/?lang=nl Good articles coming soon to offset the bad karma for this shameless plug ;) Update: A couple of stats about the current codebase. According to wc (including whitespace and comments) we currently have: Python: 3,363,188 characters, 87926 lines, 655 files Javascript: 940,536 characters, 24229 lines, 77 files Share and Enjoy: -
South 0.7 RC1
It's that time of the year again, when a new South release rears its well-refactored, database-independent head.If you've been following the development of South at all, you'll know that 0.7 has been quite a while in the making. I've been busy working away at a big code refactor, along with Simon Law, who has gained the title of "Knowing Too Much About Migrations". However, there are some user-facing changes as well, some quite significant. While my release notes go into some detail on what's new, the major changes include: New command names.The old startmigration was getting a little overloaded and wasn't too well-named, so it's been split into schemamigration and datamigration commands. No more issues with missing defaults. South realises you need a default for NOT NULL columns now, and prompts you if you forget to specify one as you're making the migration, instead of dying when you try to apply it. Django 1.2 and MultiDB support. As well as supporting the latest and greatest incarnation of the universe's best web framework, 0.7 also has some limited MultiDB support, in the form of a --database option (that works like the option of the same name on the new syncdb command … -
Django query analyzer
One of the things I wanted to work on at the DjangoSki sprints was a django query analyzer. The basic premise is that I want to create an easy way for users to experiment with and play with the ORM to produce the queries that they want. If you are new to Django, figuring out the ORM is one the first things you will need to tackle and it can be a little opaque. There's some ways to play with it at the shell, or use the debug toolbar, but these can be a little limited and unhelpful to newbies. The main interface would ideally be a series of options introspected from the model. Choose a model, choose a query manager, then add in multiple filter queries. This would not be able to capture everything and you'd always need an opt out clause of a text area where you can enter anything you want. This is pretty similar to the GUI's you'll get with most SQL servers, its just the Django ORM layer on top of it. Sadly I didn't get much chance apart from some time on Thursday afternoon. But a whole bunch of other people did including Stefan … -
Caktus Consulting Group hosts 2nd Django sprint in NC Triangle area
Django is a tool we use every day to build fantastic web apps here at Caktus, and a development sprint is a concerted, focused period of time in which developers meet in the same space to get things done on a project. -
Maintain Constants.py through Data Migration
This post will show you how to create a local_contants.py file using Django South. If you're not familiar with South, it's a data migration tool. Stated differently, it's a tool that helps keep your database changes current across different sandboxes and server environments. The reason you may want to have constants is when you have a type model instance that you want to reference in your code for decision logic. For example, you might display things differently if your contact method type ID is 1 (email) vs 2 (phone). Typically, you keep these in constants.py file. Although sometimes you can put this data in a fixture, for various reasons sometimes fixtures is not the ideal solution. The code below is designed to be run inside a migration to update your local_constants.py file with data that you just migrated. local_constants.py is a locally maintained file. This means, that like your local_settings.py, it should not be in the repo. For example: set_constant('/home/projects/sample/local_constants.py', 'STAMP_MW_ID', 42 , 'Set from sample.0007_add_constants.py') The constant searching could be improved, feel free to post enhancements! def set_constant(file, constant, value, comment = ''): ''' Search through file for the constant and either adds it to the end or updates … -
Configuring Nginx as a Pass Through Image Proxy
This post shows how to setup Nginx has a pass-through image proxy server. This is useful for local sandboxes, UAT and QA servers where you copy production database down to but don't want to copy all the user generated images to the non production environment. The problem You have a production database with lots of images uploaded by users. For example, NationalGeographic.com has over 11gb of user uploaded images. When you download a data dump of the production DB, it has links to all these images which you don't have. You either have to download and sync all the images locally every time you copy the database, live with broken images or point your static images to the prod server. Copying images locally is the brute force method and will work. If you have all day to sync up images. Pointing to the images in prod also works, but if you upload your own images to test functionality... You will not be able to see those new images. Solution Setup nginx to look for static images locally and if it doesn't find it, go to the production server and pull the image. This works nicely because you can upload images … -
2Ze.us Updates
There has been quite a bit of recent activity in my 2ze.us project since I first released it nearly a year ago. My intent was not to become a competitor with bit.ly, is.gd, or anyone else in the URL-shortening arena. I created the site as a way for me to learn more about Google's AppEngine. It didn't take very long to get it up and running, and it seemed to work fairly well. AppEngine and Extensions I was able to basically leave the site alone on AppEngine for several months--through about September 2009. In that time, I came up with a Firefox extension to make its use more convenient. The extension allows you to quickly get a shortened URL for the page you're currently looking at, and a couple of context menu items let you get a short URL for things like specific images on a page. Also included in the extension is a preview for 2ze.us links. The preview can tell you the title and domain of the link's target. It can tell you how much smaller the 2ze.us URL is compared to the full URL. Finally, it displays how many times that particular 2ze.us link has been clicked. … -
On Security and Python's Exec
A recent project at work has renewed my aversion to Python's exec statement--particularly when you want to use it with arbitrary, untrusted code. The project requirements necessitated the use of exec, so I got to do some interesting experiments with it. I've got a few friends who, until I slapped some sense into them, were seemingly big fans of exec (in Django projects, even...). This article is for them and others in the same boat. Take this example: #!/usr/bin/env python import sys dirname = '/usr/lib/python2.6/site-packages' print dirname, 'in path?', (dirname in sys.path) exec """import sys dirname = '/usr/lib/python2.6/site-packages' print 'In exec path?', (dirname in sys.path) sys.path.remove(dirname) print 'In exec path?', (dirname in sys.path)""" print dirname, 'in path?', (dirname in sys.path) Take a second and examine what the script is doing. Done? Great... So, the script first makes sure that a very critical directory is in my PYTHONPATH: /usr/lib/python2.6/site-packages. This is the directory where all of the awesome Python packages, like PIL, lxml, and dozens of others, reside. This is where Python will look for such packages when I try to import and use them in my programs. Next, a little Python snippet is executed using exec. Let's say this snippet … -
Pip pip hurra!
Què voleu, estic content de veure que una eina com pip funciona tan bé. Pip és una eina per a la instal·lació de paquets i dependències per Python, molt més avançada que easy_install ja que permet tot el que feia easy_install però a més, permet mantenir d'una manera fàcil un arxius amb totes les dependències del nostre projecte. Ens permet instal·lar paquests de Python des dels repositoris de Pypi, des de subversion, git, mercurial a través d'un fitxer de requeriments simple i a la vegada funcional. Mode batalleta on: Ahir vespre estava fent feina amb un projecte mascota que tinc, un motor de reserves per hotels i cadenes hoteleres fet amb Python i Django. El projecte necessita de força llibreries: la darrera versió de django, nose pels tests, sphinx per la documentació, django debug toolbar, django extensions, south per la migració de dades, ipython, ipdb, pep8, coverage, pytlint. Tot això (i algunes més que s'hi afegiran) constitueixen l'entorn de desnvolupament del projecte. Actualment faig feina amb tres ordinadors: el fix (el PPC del que tant he parlat per aquí), portàtil un Dell D820 i un Dell de 10". Segons on estic i el que he de fer en faig servir … -
Updates for django-lastfm and django-sphinxdoc
After reading The Hitchhiker’s Guide to Packaging I update my packages for django-lastfm and django-sphinxdoc. There are no functionional improvements, so you don’t need to update them. -
Updates for django-lastfm and django-sphinxdoc
After reading The Hitchhiker’s Guide to Packaging I update my packages for django-lastfm and django-sphinxdoc. There are no functionional improvements, so you don’t need to update them. -
Announcing django-moderation
django-moderation is reusable application for Django framework, that allows to moderate any model objects. Code can be found at http://github.com/dominno/django-moderation Possible use cases: User creates his profile, profile is not visible on site. It will be visible on site when moderator approves it. User changes his profile, old profile data is visible on site. New data will be visible on site when moderator approves it. Features: configurable admin integration(data changed in admin can be visible on site when moderator approves it) moderation queue in admin html differences of changes between versions of objects configurable email notifications custom model form that allows to edit changed data of object 100% PEP8 correct code test coverage > 80% Requirements python >= 2.4 django >= 1.1 Installation Download source code from http://github.com/dominno/django-moderation and run installation script: $> python setup.py install Configuration Add to your INSTALLED_APPS in your settings.py: moderation Run command manage.py syncdb Register Models with moderation from django.db import models from moderation import moderation class YourModel(models.Model): pass moderation.register(YourModel) Register admin class with your Model from django.contrib import admin from moderation.admin import ModerationAdmin class YourModelAdmin(ModerationAdmin): """Admin settings go here.""" admin.site.register(YourModel, YourModelAdmin) If you want to disable integration of moderation in admin, add admin_intergration_enabled = … -
Decoupled Django Apps and the Beauty of Generic Relations
Like just about everyone else, we've written our own suite of tools to help with building complex content management systems in Django here at Caktus. We reviewed a number of the existing CMSes out there, but in almost every case the navigation and page structure were so tightly coupled the system broke down when it came time to add additional, non-CMS pages. -
Cache Machine: Automatic caching for your Django models
Cache Machine: Automatic caching for your Django models. This is the third new ORM caching layer for Django I’ve seen in the past month! Cache Machine was developed for zamboni, the port of addons.mozilla.org to Django. Caching is enabled using a model mixin class (to hook up some post_delete hooks) and a custom caching manager. Invalidation works by maintaining a “flush list” of dependent cache entries for each object—this is currently stored in memcached and hence has potential race conditions, but a comment in the source code suggests that this could be solved by moving to redis. -
Django User Profiles - Simple yet powerful
So you're building a web application, and using the excellent contrib.auth subsystem to manage user accounts. Most probably you need to store additional information about your users, but how? Django profiles to the rescue! Django provides a lightweight way of defining a profile object linked to a given user. The profile object can differ from project to project, and it can even handle different profiles for different sites served from the same database. In a nutshell, using Django profiles consists of 3 steps: Define a model that holds the profile information. Tell Django where to look for the profile object. Create the user profile as needed. Defining the user profile model The only requirement Django places on this model is that it have a unique ForeignKey to the User model, and is called user. Other than that, you can define any other fields you like. For our example, we'll create 2 user profile fields (url and company). account/models.py from django.db import models from django.contrib.auth.models import User class UserProfile(models.Model): user = models.ForeignKey(User, unique=True) url = models.URLField("Website", blank=True) company = models.CharField(max_length=50, blank=True) Tell Django about the profile object Accessing a users profile is done by calling user.get_profile(), but in order … -
Django User Profiles - Simple yet powerful
So you're building a web application, and using the excellent contrib.auth subsystem to manage user accounts. Most probably you need to store additional information about your users, but how? Django profiles to the rescue! Django provides a lightweight way of defining a profile object linked to a given user. The profile object can differ from project to project, and it can even handle different profiles for different sites served from the same database. In a nutshell, using Django profiles consists of 3 steps: Define a model that holds the profile information. Tell Django where to look for the profile object. Create the user profile as needed. Defining the user profile model The only requirement Django places on this model is that it have a unique ForeignKey to the User model, and is called user. Other than that, you can define any other fields you like. For our example, we'll create 2 user profile fields (url and company). account/models.py from django.db import models from django.contrib.auth.models import User class UserProfile(models.Model): user = models.ForeignKey(User, unique=True) url = models.URLField("Website", blank=True) company = models.CharField(max_length=50, blank=True) Tell Django about the profile object Accessing a users profile is done by calling user.get_profile(), but in order … -
Django User Profiles - Simple yet powerful
So you're building a web application, and using the excellent contrib.auth subsystem to manage user accounts. Most probably you need to store additional information about your users, but how? Django profiles to the rescue! Django provides a lightweight way of defining a profile object linked to a given user. The profile object can differ from project to project, and it can even handle different profiles for different sites served from the same database. In a nutshell, using Django profiles consists of 3 steps: Define a model that holds the profile information. Tell Django where to look for the profile object. Create the user profile as needed. Defining the user profile model The only requirement Django places on this model is that it have a unique ForeignKey to the User model, and is called user. Other than that, you can define any other fields you like. For our example, we'll create 2 user profile fields (url and company). account/models.py from django.db import models from django.contrib.auth.models import User class UserProfile(models.Model): user = models.ForeignKey(User, unique=True) url = models.URLField("Website", blank=True) company = models.CharField(max_length=50, blank=True) Tell Django about the profile object Accessing a users profile is done by calling user.get_profile(), but in order … -
Refugee Buddy: a project of OzSiCamp Sydney 2010
Last weekend, I attended Social Innovation Camp Sydney 2010. SiCamp is an event where several teams have one weekend in which to take an idea for an online social innovation technology, and to make something of it. Ideally, the technology gets built and deployed by the end of the camp, but if a team doesn't reach that stage, simply developing the concept is an acceptable outcome as well. I was part of a team of seven (including our team leader), and we were the team that built Refugee Buddy. As the site's slogan says: "Refugee Buddy is a way for you to welcome people to your community from other cultures and countries." It allows regular Australians to sign up and become volunteers to help out people in our community who are refugees from overseas. It then allows refugee welfare organisations (both governmnent and independent) to search the database of volunteers, and to match "buddies" with people in need. Of the eight teams present at this OzSiCamp, we won! Big congratulations to everyone on the team: Oz, Alex, James, Daniela, Tom, (and Jeremy — that's me!) and most of all Joy, who came to the camp with a great concept, and …