Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Benchmarking Celery
Before you even go there, I’ll preface this with YMMV. This little post is to document a benchmark that I did for an internal use case, in the hopes that it’ll be helpful for others. As a benchmark, I wasn’t … Continue reading → -
F() objects and QuerySet.update() support in djangoappengine
As some of you already noticed, we added supported for QuerySet.update() and F() objects as part of some features we currently need for our startup pentotype. Finally, it's possible to use simple transactions on App Engine via Django-nonrel :) Let's see how it works. Django's beauty In order to show what we gain by using Django's QuerySet.update() method and F() objects let me illustrate the code differences between the old djangoappengine version and the new one using a simple transaction which increments the value of a counter by a specific amount. In both cases we have the following model definition: # models.py from django.db import models class Accumulator(models.Model): counter = models.IntegerField() name = models.CharField(max_length=500) The old version looks like this: from google.appengine.ext import db def increment_counter(pk, amount): obj = Accumulator.objects.get(pk=pk) obj.counter += amount obj.save() db.run_in_transaction(increment_counter, 1, 5) whereas the new one looks like this: from django.db.models import F Accumulator.objects.filter(pk=1).update(counter=F('counter') + 5) Obviously, it's more elegant to update a counter using QuerySet.update() and F() objects because it's much clearer and we have to write less code, thus resulting in more productivity. Additionally, it's possible to do more complicated transactions, for example, updating multiple entities using Django's elegant syntax: Accumulator.objects.filter(name__startswith='simple').update(counter=F('counter') + 1) … -
New kung-fu in django-uni-form 0.8.0
This won’t be a new official release announcement as Daniel already did the honors. I’m now the co-lead developer of django-uni-form and in this post I will try to go over some examples that teach you new kung-fu techniques. But before doing so, let me emphasize how cool this project is and how many new nice features are packed in the new version 0.8.0. If you like DRY principles and don’t think your Django forms are DRY enough using built-in filters, you should check it! if you haven’t yet. To explain some of the new features, let’s use a real form and a real example, so it’s easier to follow how django-uni-form works and what has been enhanced. The following form will be used from now onwards to exemplify the new features in django-uni-form. I’m using different types of form fields to demonstrate how django-uni-form can work with any built-in widget or form field or any other custom field that you have defined. That is, django-uni-form plugs well with other form apps. from django import forms class ArticleFeedbackForm(forms.Form): like_example = forms.TypedChoiceField( label = _("¿Do you like this article?"), choices = ((1, "Yes"), (0, "No")), coerce = lambda x: bool(int(x)), widget … -
New kung-fu in django-uni-form 0.8.0
This won’t be a new official release announcement as Daniel already did the honors. I’m now the co-lead developer of django-uni-form and in this post I will try to go over some examples that teach you new kung-fu techniques. But before doing so, let me emphasize how cool this project is and how many new nice features are packed in the new version 0.8.0. If you like DRY principles and don’t think your Django forms are DRY enough using built-in filters, you should check it! if you haven’t yet. To explain some of the new features, let’s use a real form and a real example, so it’s easier to follow how django-uni-form works and what has been enhanced. The following form will be used from now onwards to exemplify the new features in django-uni-form. I’m using different types of form fields to demonstrate how django-uni-form can work with any built-in widget or form field or any other custom field that you have defined. That is, django-uni-form plugs well with other form apps. from django import forms class ArticleFeedbackForm(forms.Form): like_example = forms.TypedChoiceField( label = _("¿Do you like this article?"), choices = ((1, "Yes"), (0, "No")), coerce = lambda x: bool(int(x)), widget … -
Shiv The Third - Return of Tutorial
Continuing from my previous posts on Shiv, Shiv - A wrapper over Django and Shiv - Part Deux, I will now try to explain about various components involved in Shiv. In this post we will talk about Media and Element. In later parts, we will explore Tabs, Boxes, Widgets, Pages, and Caching. An app using Shiv should have the following files 1. page.py: This will contain the definition for all Page container classes 2. box.py: This will contain the definition for all Box container classes 3. widget.py: This will contain the definition for all Widget container classes 4. tab.py: This will contain the definition for all Tab container classes 5. element.py: This will contain the definition for all Element container classes 6. media.py: This will contain the definition for all Media classes Media Media classes define the various media used by all the containers of the Project. Shiv uses a naming convention for media classes. The media class of a container class named “ABC” should be “ABCMedia” and it must be derived from shiv.media.Media. Media class has following class variables a. template: This is the path of the template file. b. css: A list of css file paths which this … -
Extending templates from a specific Django app
A while ago (well, actually a long time ago since I had this blog post laying around as a draft, until I stumbled across a stack overflow question that this post would answer) I wanted to customize Django's admin app, by adding a link to a statistics page that I had built, on the index.html page of the admin app. I could have copied the index.html from the templates directory in the admin app, to my project's templates directory and added my link, but this would have given me a maintenance task to keep Django's admin templates up to date in future versions. So what I really wanted to do was to define my own admin/index.html file in the project's templates directory, and then in my index template extend the index template from the admin app. However this isn't supported by Django be default. When I searched the web I found all sort of solutions to the problem, some involving symlinking the admin's index.html to another path and then extending the symlink, but that wasn't an option for me since I develop on both Windows and Unix, and besides, it didn't feel like a very clean solution. Finally I found … -
P.J. Eby on PyPI
P.J. Eby: The cardinal rule of successful groupware is that those who put information into the system must receive a proportional benefit for their efforts, or those who want to get information out of the system will not see anything coming out. -
Custom 404 Not Found page with Django CMS…
… or how to make user editable 404 page that stays in the pages tree of the CMS Basics: Yes you need it! You need 404 page cause you never know what may happen to a link: bad link paste, obsolete or deleted article, someone just playing with your URLs etc. It is better for [...] -
Shiv - Part Deux
After debating whether to release early or release well, I have settled for the former. I hope that once the code is out in the open and I get ridiculed for the lousy code quality, it will motivate me to find time more aggressively to correct and refine the framework. I will try to find some time to continue my little tutorial of Shiv with sample applications in the next installment. In the meantime, here is the link to the git repository. Have a look and feel free to ask me any question that you might have. https://github.com/lzdev/Shiv Part 1 | Part 3 -
Measure your code
I found a cool tool today to measure code: metrics. It measures SLOC, comments and cyclomatic complexity. It’s easy to install: pip install pygments metrics Run this in your project’s root: metrics -v `find . -type f \( -iname "*.css" -or -iname "*.py" -or -iname "*.js" -or -iname "*.html" -or -iname "*.txt" \) \! -path "*/migrations/*.py" -print` I have a django project so I added \! -path "*/migrations/*.py" to skip any files that are in a migrations dir (I’d skip the automatically generated south migrations). You probably bundle other libraries or apps in your source tree (eg: jquery or that nice django app the author didn’t bother to make a setup.py script for) so you want to measure only some specific paths. Eg, to collect stats only for files in src/foobar, lib/tools and src/otherbar: metrics -v `find src/foobar lib/tools src/otherbar -type f \( -iname "*.css" -or -iname "*.py" -or -iname "*.js" -or -iname "*.html" -or -iname "*.txt" \) \! -path "*/migrations/*.py" -print` If you work on multiple projects you can make a script or alias for this: metrics -v `find \`cat METRICS\` -type f \( -iname "*.css" -or -iname "*.py" -or -iname "*.js" -or -iname "*.html" -or -iname "*.txt" \) … -
Measure your code
I found a cool tool today to measure code: metrics. It measures SLOC, comments and cyclomatic complexity. It's easy to install: pip install pygments metrics Run this in your project's root: metrics -v `find . -type f \( -iname "*.css" -or -iname "*.py" -or -iname "*.js" -or -iname "*.html" -or -iname "*.txt" \) \! -path "*/migrations/*.py" -print` I have a django project so I added \! -path "*/migrations/*.py" to skip any files that are in a migrations dir (I'd skip the automatically generated south migrations). You probably bundle other libraries or apps in your source tree (eg: jquery or that nice django app the author didn't bother to make a setup.py script for) so you want to measure only some specific paths. Eg, to collect stats only for files in src/foobar, lib/tools and src/otherbar: metrics -v `find src/foobar lib/tools src/otherbar -type f \( -iname "*.css" -or -iname "*.py" -or -iname "*.js" -or -iname "*.html" -or -iname "*.txt" \) \! -path "*/migrations/*.py" -print` If you work on multiple projects you can make a script or alias for this: metrics -v `find \`cat METRICS\` -type f \( -iname "*.css" -or -iname "*.py" -or -iname "*.js" -or -iname "*.html" -or -iname "*.txt" \) … -
Measure your code
I found a cool tool today to measure code: metrics. It measures SLOC, comments and cyclomatic complexity. It's easy to install: pip install pygments metrics Run this in your project's root: metrics -v `find . -type f \( -iname "*.css" -or -iname "*.py" -or -iname "*.js" -or -iname "*.html" -or -iname "*.txt" \) \! -path "*/migrations/*.py" -print` I have a django project so I added \! -path "*/migrations/*.py" to skip any files that are in a migrations dir (I'd skip the automatically generated south migrations). You probably bundle other libraries or apps in your source tree (eg: jquery or that nice django app the author didn't bother to make a setup.py script for) so you want to measure only some specific paths. Eg, to collect stats only for files in src/foobar, lib/tools and src/otherbar: metrics -v `find src/foobar lib/tools src/otherbar -type f \( -iname "*.css" -or -iname "*.py" -or -iname "*.js" -or -iname "*.html" -or -iname "*.txt" \) \! -path "*/migrations/*.py" -print` If you work on multiple projects you can make a script or alias for this: metrics -v `find \`cat METRICS\` -type f \( -iname "*.css" -or -iname "*.py" -or -iname "*.js" -or -iname "*.html" -or -iname "*.txt" \) … -
Be careful how you use static variables in forms
Working on django-uni-form I came across with a weird situation and it took me some time to figure out what was going on. I wouldn’t say it was a bug, it was more a misuse or a documentation problem. After that, I realized other coders make the same mistake that was affecting us, so I thought about writing an article for warning Python/Django programmers. If you are building a Django application in which you add attributes to a form, that are not form fields, like in this example: class ExampleForm(forms.Form): description = forms.CharField( label = u"Short description", max_length = 40, ) type_of_form = 'dangerous' You should know that every attribute that is not a form field, such as type_of_form, is static or a class-wide variable. Let’s see what this means and please stay with me till the end, don’t switch channel. If you handle a form instance in one of your views and change type_of_form value: form = ExampleForm(request.POST) form.type_of_form = "secure" Then type_of_form turned into an instance-level variable. Which means only that specific form instance has a type_of_form set to ‘secure’. You can still access the class wide variable, using the class name: >>> ExampleForm.type_of_form 'dangerous' Things get complicated … -
Be careful how you use static variables in forms
Working on django-uni-form I came across with a weird situation and it took me some time to figure out what was going on. I wouldn’t say it was a bug, it was more a misuse or a documentation problem. After that, I realized other coders make the same mistake that was affecting us, so I thought about writing an article for warning Python/Django programmers. If you are building a Django application in which you add attributes to a form, that are not form fields, like in this example: class ExampleForm(forms.Form): description = forms.CharField( label = u"Short description", max_length = 40, ) type_of_form = 'dangerous' You should know that every attribute that is not a form field, such as type_of_form, is static or a class-wide variable. Let’s see what this means and please stay with me till the end, don’t switch channel. If you handle a form instance in one of your views and change type_of_form value: form = ExampleForm(request.POST) form.type_of_form = "secure" Then type_of_form turned into an instance-level variable. Which means only that specific form instance has a type_of_form set to ‘secure’. You can still access the class wide variable, using the class name: >>> ExampleForm.type_of_form 'dangerous' Things get complicated … -
DjangoCon Europe videos posted
DjangoCon Europe 2011 videos online A bit late to the game perhaps, since people already started tweeting links to the videos before me having time to actually link the videos to the talks. But hey, that shouldn’t spoil the game: The videos are now online, and can be found in te schedule on the details pages of all the talks, including the slides. For example to check out Eric Florenzano’s excellent opening keynote, check out this talk page. The video of Alex’ talk on monday is forthcoming. I would like to use the opportunity to thank our Kryptonite sponsors, who made such a large contribution to DjangoCon Europe 2011, once more: Fabrique: Who in addition to being a kryptonite sponsor also sponsored the cocktail bar on Monday and the massages/relaxing area on Tuesday. I amsterdam: Who in addition to being a kryptonite sponsor also sponsored the free bikes for conference goers and the massages during both the sprint days. A warm thank you from all of us. -
Award Winning Satchmo Sites
The team at Pemaquid Communications have been successfully using Satchmo and Django to create innovative sites for their clients. Recently they won several Best of the Web awards at the TechMaine Gala. -
django-meio-easytags 0.4 released!
I just released the version 0.4 of the django-meio-easytags. I added a subclass of django’s default template tags Library. And now it’s easier to create a template tag. Take a look. Projects page Read the Docs Download from Github -
django-meio-easytags 0.3 released!
I released today the version 0.3 of django-meio-easytags. Now it supports template tags that accepts positional arguments (*args) and keyword arguments (**kwargs). If you don’t know how to use this, take a look at Python FAQ. In this release I included some documentation and created a page for the project. Any doubts, suggestions, feature requests, feel [...] -
Documenting Django pluggable apps with Sphinx
I decided to document my Django projects with the same tool used by Django team: Sphinx. It is a very good documenting tool, and was used for many other projects, including the Python Project itself. But it has a simple problem with Django, that I found the solution rlazo’s blog. But it still has some problems, [...] -
django-meio-easytags released!
django-meio-easytags An easy way to create and parse custom template tags for Django's templating system. -
Django ORM now supports fields references in filters
Today was added a new feature to django ORM. Now it supports references to fields in filters expressions. Just checkout the SVN version and enjoy it. Before this update, queryset could be filtered only by absolute values. queryset.filter(field='absolute value') Will generate somthing like this: SELECT * FROM table_name WHERE field = 'absolute value'; Now you can filter by another’s table [...] -
get_first_object_or_none shortcut for Django
I will talk about a shortcut I developed for the Django framework and always use in my apps. This code is aimed in making a quik shortcut to obtain the first object of a queryset if it exists or None otherwise. It’s very useful when you want to display the last news in the first page [...] -
Arquivos do Mini curso de Django disponibilizados
No dia 24 de abril de 2009, no SENAC em Natal/RN, ocorreu o FLISOL. Neste evento, eu ministrei um mini curso de django. Então estou disponibilizando tanto os arquivos_mini_curso desenvolvido durante o curso, como os slides. Mini curso introdutório ao DjangoView more presentations from vbmendes. -
Festival Latino-americano de Instalação de Software Livre
Venho através deste convidá-los ao FLISOL/RN 2009. O Festival Latino-americano de Instalação de Software Livre do RN irá acontecer no dia 25 de abril de 2009 no SENAC em Natal. No evento eu irei ministrar um mini-curso introdutório ao framework Django das 14:00 as 17:00 horas, cujo objetivo é formar pessoas com conhecimentos básicos acerca do [...] -
Reffering to Django docs from your docs using Sphinx
Sphinx is a great documentation tool, and one of it’s built-in extensions is sphinx.ext.intersphinx. It simply takes your objects references for other projects and converts to links in the other project’s documentation. In sphinx-quickstart command, it asks if you want to add this extension. If so, It adds this code to your conf.py file: extensions = ['sphinx.ext.intersphinx'] intersphinx_mapping [...]