Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Python comparisons speed depends from the result
Recently I decided to check whether “less than or equal”(<=) is slower than “bigger”(>) and I was surprised from the result. In my case “bigger” was slower. I was amazed, according to the simple logic in the case of less then or equal we need one or two operation(for example we first check for equality [...] -
Using Sass with django-mediagenerator
This is the second post in our django-mediagenerator series. If you haven't read it already, please read the first post before continuing: django-mediagenerator: total asset management What is Sass? Great that you ask. :) Sass is a high-level language for generating CSS. What? You still write CSS by hand? "That's so bourgeois." (Quick: Who said that in which TV series?) Totally. ;) Sass to CSS is like Django templates to static HTML. Sass supports variables (e.g.: $mymargin: 10px), reusable code snippets, control statements (@if, etc.), and a more compact indentation-based syntax. You can even use selector inheritance to extend code that is defined in some other Sass file! Also, you can make computations like $mymargin / 2 which can come in very handy e.g. for building fluid grids. Let's see a very simple example of the base syntax: .content padding: 0 p margin-bottom: 2em .alert color: red This produces the following CSS code: .content { padding: 0; } .content p { margin-bottom: 2em; } .content .alert { color: red; } So, nesting can help reduce repetition and the cleaner syntax also makes Sass easier to type and read. Once you start using the advanced features you won't ever want to … -
Why I moved to Django from PHP
After working for years with PHP, I developed a project using Django and loved every bit of it. -
Finding the closest data center using GeoIP and indexing
We are about to release the TurnKey Linux Backup and Migration (TKLBAM) mechanism, which boasts to be the simplest way, ever, to backup a TurnKey appliance across all deployments (VM, bare-metal, Amazon EC2, etc.), as well as provide the ability to restore a backup anywhere, essentially appliance migration or upgrade. Note: We'll be posting more details really soon - In this post I just want to share an interesting issue we solved recently. Backups need to be stored somewhere - preferably somewhere that provides unlimited, reliable, secure and inexpensive storage. After exploring the available options, we decided on Amazon S3 for TKLBAM's storage backend. The problem Amazon have 4 data centers called regions spanning the world, situated in North California (us-west-1), North Virginia (us-east-1), Ireland (eu-west-1) and Singapore (ap-southeast-1). The problem: Which region should be used to store a servers backups, and how should it be determined? One option was to require the user to specify the region to be used during backup, but, we quickly decided against polluting the user interface with options which can be confusing, and opted for a solution that could automatically determine the best region. The solution The below map plots the countries/states with their associated Amazon region: Generated automatically using Google Maps API … -
Finding the closest data center using GeoIP and indexing
We are about to release the TurnKey Linux Backup and Migration (TKLBAM) mechanism, which boasts to be the simplest way, ever, to backup a TurnKey appliance across all deployments (VM, bare-metal, Amazon EC2, etc.), as well as provide the ability to restore a backup anywhere, essentially appliance migration or upgrade. Note: We'll be posting more details really soon - In this post I just want to share an interesting issue we solved recently. Backups need to be stored somewhere - preferably somewhere that provides unlimited, reliable, secure and inexpensive storage. After exploring the available options, we decided on Amazon S3 for TKLBAM's storage backend. The problem Amazon have 4 data centers called regions spanning the world, situated in North California (us-west-1), North Virginia (us-east-1), Ireland (eu-west-1) and Singapore (ap-southeast-1). The problem: Which region should be used to store a servers backups, and how should it be determined? One option was to require the user to specify the region to be used during backup, but, we quickly decided against polluting the user interface with options which can be confusing, and opted for a solution that could automatically determine the best region. The solution The below map plots the countries/states with their associated Amazon region: Generated automatically using Google Maps API … -
Finding the closest data center using GeoIP and indexing
We are about to release the TurnKey Linux Backup and Migration (TKLBAM) mechanism, which boasts to be the simplest way, ever, to backup a TurnKey appliance across all deployments (VM, bare-metal, Amazon EC2, etc.), as well as provide the ability to restore a backup anywhere, essentially appliance migration or upgrade. Note: We'll be posting more details really soon - In this post I just want to share an interesting issue we solved recently. Backups need to be stored somewhere - preferably somewhere that provides unlimited, reliable, secure and inexpensive storage. After exploring the available options, we decided on Amazon S3 for TKLBAM's storage backend. The problem Amazon have 4 data centers called regions spanning the world, situated in North California (us-west-1), North Virginia (us-east-1), Ireland (eu-west-1) and Singapore (ap-southeast-1). The problem: Which region should be used to store a servers backups, and how should it be determined? One option was to require the user to specify the region to be used during backup, but, we quickly decided against polluting the user interface with options which can be confusing, and opted for a solution that could automatically determine the best region. The solution The below map plots the countries/states with their associated Amazon region: Generated automatically using Google Maps API … -
Haanga vs Django vs Tornado
L'altra dia es va alliberar un llenguatge de plantilles inspirant amb Django anomenat Haanga patrocinat per Meneame.net. Crec que això és una bono notícia, tenc la mala sort que quan he de tocar codi PHP sempre m'he trobat en que la separació de codi i lògica de presentació directament no hi és. Supòs que perquè els llenguatges de plantilles que hi ha són massa feixucs com per a que un programador de PHP se'ls plantegi en el seu dia a dia. La sintaxi de plantilles de Django és lleugera per al programador/maquetador: és bona d'aprendre i molt poc intrussiva. Així que Haanga al meu entendre és un gran avanç, ja que té la senzillesa de Django i lleva l'excusa de la velicitat que sovint et donen alguns progrmadors de PHP per posar-ho tot junt, ja que compila les plantilles a PHP, amb la qual cosa tenim tots els beneficis i molt pocs emperòs. Ricardo al seu blog fa una comparació de velocitat però s'ha de dir que no és ben bé justa, ja que no estam comparant el mateix, no en el cas de Django i Haanga al manco, ja que la comparació s'està fent en peticions per segon i … -
Getting the related item in an aggregate
There's a question I see quite a lot at StackOverflow and the Django Users group regarding aggregation in Django. It goes like this: I know how to annotate a max/min value for a related item on each item in a queryset. But how do I get the actual related item itself? I wish this was easier than it actually is. The problem is that in the underlying SQL, annotating the value is a simple aggregation query on the related item, whereas getting the entire object means moving to a complicated dependent subquery. To illustrate, take these models: class Blog(models.Model): name = models.CharField(max_length=64) class Entry(models.Model): blog = models.ForeignKey(Blog) added = models.DateTimeField(auto_now_add=True) text = models.TextField() Getting the date of the latest Entry for each Blog is simple: blogs = Blog.objects.annotate(Max('entry__added')) and the underlying SQL is just as simple: SELECT blog.id, blog.name, MAX(entry.added) FROM blog_blog blog JOIN blog_entry entry on entry.blog_id = blog.id GROUP BY blog.id But that doesn't work if you want the whole Entry object. You need to do something much more complicated: SELECT blog.id, blog.name, entry.id, entry.added, entry.text FROM blog_blog blog, blog_entry entry WHERE entry.id = ( SELECT e2.id FROM blog_entry e2 WHERE e2.blog_id = blog.id ORDER BY e2.added LIMIT … -
Getting the related item in an aggregate
There's a question I see quite a lot at StackOverflow and the Django Users group regarding aggregation in Django. It goes like this: I know how to annotate a max/min value for a related item on each item in a queryset. But how do I get the actual related item itself? I wish this was easier than it actually is. The problem is that in the underlying SQL, annotating the value is a simple aggregation query on the related item, whereas getting the entire object means moving to a complicated dependent subquery. To illustrate, take these models: class Blog(models.Model): name = models.CharField(max_length=64) class Entry(models.Model): blog = models.ForeignKey(Blog) added = models.DateTimeField(auto_now_add=True) text = models.TextField() Getting the date of the latest Entry for each Blog is simple: blogs = Blog.objects.annotate(Max('entry__added')) and the underlying SQL is just as simple: SELECT blog.id, blog.name, MAX(entry.added) FROM blog_blog blog JOIN blog_entry entry on entry.blog_id = blog.id GROUP BY blog.id But that doesn't work if you want the whole Entry object. You need to do something much more complicated: SELECT blog.id, blog.name, entry.id, entry.added, entry.text FROM blog_blog blog, blog_entry entry WHERE entry.id = ( SELECT e2.id FROM blog_entry e2 WHERE e2.blog_id = blog.id ORDER BY e2.added LIMIT … -
South 0.7.2
After a slightly too long hiatus, I've released the second bugfix release of the 0.7 series.There's not a whole lot new and exciting in this one, just lots of small fixes - bugfixes, removal of some unused variables, a few more command line arguments where they should have been already, that sort of thing. You can read more in the release notes. In other news, I'll be giving a talk at DjangoCon US 2010 which, for once, isn't about South, but instead covers a more broad spectrum of databases and schemas, in particular encompassing schemaless databases (which do still need migrations, in some form), so if you're going to be at the conference, come along, or just catch me outside of a session if you want to talk. I apologise for the slightly slow rate of work on South as of late, but I'm in the middle of moving cities. After next week, I'll be settled in London, and hopefully work will progress faster. I'll also be looking for contract/consulting work after next week, so if you'd like to hire me, see my 'corporate site'. -
South 0.7.2
After a slightly too long hiatus, I've released the second bugfix release of the 0.7 series. There's not a whole lot new and exciting in this one, just lots of small fixes - bugfixes, removal of some unused variables, a few more command line arguments where they should have been already, that sort of thing. You can read more in the release notes. In other news, I'll be giving a talk at DjangoCon US 2010 which, for once, isn't about South, but instead covers a more broad spectrum of databases and schemas, in particular encompassing schemaless databases (which do still need migrations, in some form), so if you're going to be at the conference, come along, or just catch me outside of a session if you want to talk. I apologise for the slightly slow rate of work on South as of late, but I'm in the middle of moving cities. After next week, I'll be settled in London, and hopefully work will progress faster. I'll also be looking for contract/consulting work after next week, so if you'd like to hire me, see my 'corporate site'. -
Python Edinburgh
Python Edinburgh is user group for Pythonistas in (surprisingly) Edinburgh. This is a kick start of a group that died out unfortunately and only met once this year. Find out more at the new (but basic) website and follow us on twitter or join the mailing list. The group is going to be meeting on the 4th Tuesday of each month. The next being on the 24th August at Bert's Bar. Hope to see some of you there - please let us know if your coming so we can get the numbers right. -
Caktus Consulting Group Welcomes Lead Developer Karen Tracey
I'm delighted to welcome Karey Tracey to our growing team of web developers here at Caktus. Karen is a core developer of the Django web framework and specializes in the development and testing of applications for the web. She is also the author of Django 1.1 Testing and Debugging, published by Packt Publishing in April, 2010. -
Customizing Django Comments: Remove Unwanted Fields
I recently added comments to a new Django site that I’m working on. Comments pose an interesting problem as they can have a number of “parents”. In my case, the parent might be a user’s “Want” a respondent’s “Have” or possibly another “Comment.” In the process of researching the best way to architect Wantbox’s comments app, I read about “polymorphic associations“, “exclusive arcs” and Django’s ContentType framework. Using this knowledge, I contemplated recreating the comment wheel, since I wanted my comment form to just be a simple “Stack Overflow-type” comment-only field and not the larger “WordPress-type” name/email/website/comment. As I explored Django’s comments framework deeper, I realized that recreating another comment app was a waste of my time and my end product would be far less feature rich than Django’s bundled commenting system. Below are my modifications which allowed me to quickly and easily twist Django comments into what I needed. My Django Comment Modifications: To customize the default comment form and comment list display, I created a “comments” directory in my root “templates” directory and simply overrode the two default comment templates “form.html” and “list.html”. My custom “/templates/comments/form.html”: {% load comments i18n %} {% if user.is_authenticated %} <form action="{% comment_form_target … -
Python Edinburgh
Python Edinburgh is user group for Pythonistas in (surprisingly) Edinburgh. This is a kick start of a group that died out unfortunately and only met once this year. Find out more at the new (but basic) website and follow us on twitter or join the mailing list. The group is going to be meeting on the 4th Tuesday of each month. The next being on the 24th August at Bert's Bar. Hope to see some of you there - please let us know if your coming so we can get the numbers right. -
nonrel-search updates: auto-completion and separate indexing
It was planned already very long to add some remaining features from gae-search to nonrel-search and since we stopped developing gae-search we decided to make some of the premium features open-source. So let's see what changed. New Features We basically changed two things in nonrel-search: first it's possible to index a model via a separate definition i.e. without having to modify the model's source itself and second you can use our auto-completion feature from the good old gae-search days. :) Separate indexing So let's say you want to index some of your models. With the old version of nonrel-search you had to add a SearchManager to each model you want to search for. With the latest version of nonrel-search you have to define these indexes separately from your model like this: # post.models from django.db import models class Post(models.Model): title = models.CharField(max_length=500) content = models.TextField() author = models.CharField(max_length=500) category = models.CharField(max_length=500) # post.search_indexes import search from search.core import porter_stemmer from post.models import Post # index used to retrieve posts using the title, content or the # category. search.register(Post, ('title', 'content','category', ), indexer=porter_stemmer) As you can see we use the new register function to make posts searchable by title, content and … -
An Update is Coming
For those who have been demanding that I post something, anything, (*cough* Noreen *cough*) I apologise for the delay, but it won't be long now. I've been using all this time to write a new version of my site, done up in Python/Django. The next version will be a watered-down version of this one (on account of the complete rewrite) but will grow with time. I may also decide to abandon all attempts at making it pretty... 'cause well... I suck at that :-) -
Showing Current Values for FileFields in Django
I am working on a dynamic form which contained multiple FileFields which could have initial values. The FileInput widget doesn't show initial values since that could expose too much about the servers underlying file system. Despite this I wanted to show the file name as user feedback. If the form was static, I could pass current file names in through the context and just be very explicit with my template code. Since the form was dynamic the template code would have to iterate though the fields, and there is no easy way to look up unrelated data at the same time. To learn some nifty tricks on how to create dynamic forms check out So you want a dynamic form on the b-list blog. Meanwhile I need a solution to pass in the initial file name data with the form. The built in initial dictionary didn't really work, and the field objects initial data member was empty. I had to look outside the form. Beyond the form to the truth: there is not form! There Is No Form A pearl of wisdom in my grasp, the form object did not matter, only the field objects were required to render a … -
Showing Current Values for FileFields in Django
I am working on a dynamic form which contained multiple FileFields which could have initial values. The FileInput widget doesn't show initial values since that could expose too much about the servers underlying file system. Despite this I wanted to show the file name as user feedback. If the form was static, I could pass current file names in through the context and just be very explicit with my template code. Since the form was dynamic the template code would have to iterate though the fields, and there is no easy way to look up unrelated data at the same time. To learn some nifty tricks on how to create dynamic forms check out So you want a dynamic form on the b-list blog. Meanwhile I need a solution to pass in the initial file name data with the form. The built in initial dictionary didn't really work, and the field objects initial data member was empty. I had to look outside the form. Beyond the form to the truth: there is not form! There Is No Form A pearl of wisdom in my grasp, the form object did not matter, only the field objects were required to render a … -
Django open inviter – contact importer – python
Django open inviter is a python port of the PHP api client for openinviter.com’s contact importer to work with Django. I build it for our fashion community, Fashiolista.com, where it is currently in production usage and fully functional. If you are a member of Fashiolista (which I highly doubt given the different audiences) you can test it by clicking find friends in your profile. Usage is extremly straight forward: from django_open_inviter.open_inviter import OpenInviter o = OpenInviter() contacts = o.contacts('example@example.com', 'test') Get the code here. Share and Enjoy: -
More reasons to go to DjangoCon!
I was thinking some more about DjangoCon next month.Capoeira - I'm known for doing one-handed cartwheels. But at last year's DjangoCon I got a chance to try my hand at Capoeira. Since then I've managed to get in some actual regular Capoeira training. My hope is to tag up with Oregon Capoeira and see how my Angola matches their Regional. Even if you've never done a cartwheel, it should still be a blast to try out!Okay, now on to listing some more talks I'm looking forward to having at the conference:Why Django sucks and how we can fix it - While Django is the king of Python web framewrks, Eric Florenzano is going to slam it hard. But he isn't going to just troll the conference, he's also going to provide us some possible solutions. The best thing of all, is that since Django is open source, we can all contribute to make it better!Pony Pwning - Django is a nicely secure framework thanks to the security focus of the community, but Adam Baldwin shows us how as developers we can make compromising mistakes. If you want to avoid being caught with your pants down on a day where you didn't wear clean underwear, go … -
Getting excited about DjangoCon US!
Djangocon starts in just a month. I'm looking forward to this event because of so many reasons. Lets go over some of them!Friends - I'll get to meet with old friends and make new ones. Rather than list names I'm going to mark a sheet of paper with the alphabet and check off letters as I meet/make a friend with the first name that matches an unmarked letter. Which makes me wonder if their is a Django app for that in the making...Portland - Great food and awesome beer at cheap prices. The wonderful thing about Portland is that the base ingredients are really good. I found I liked the simpler/cheaper things there more than fancy foods. The food carts alone are worth visiting the city.Oregon State - It is a beautiful state and since words can't do justice here is an image:Me at Mutnomah falls! The conference schedule rocks! - The talks they lined up all look really good. They range from the basics to the advanced, and include things that go beyond the technical. Some of my favorite picks from just the first day:Typewar: A Case Study - James Tauber is an incredible speaker, not to mention the founder of … -
Using oEmbed in Django
Replacing links to multimedia websites with nice embedded players, thumbs and other content using django-oembed. -
The kind of comments that will get ignored on Django's Trac
Participating in any Open Source project can be frustrating if things do not move along as quickly as you would like. Django is a fairly popular project, whose developers are volunteers with limited resources, and with a pretty big commitment to stability and backwards compatibility, so there will always be people who get frustrated. This blog post is intended to help people in that situation be helpful, and to not actually make things worse. -
Code coverage analysis in Django