Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
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
-
django-mediagenerator: total asset management
We really weren't posting often enough recently. Now we'll make up for it with an advanced new asset manager called django-mediagenerator. Those of you who used app-engine-patch might still remember a media generator. This one is completely rewritten with a new backend-based architecture and muchos flexibility for the shiny new HTML5 web-apps world (see the feature comparison table). In this post I'll give you a quick intro and after that I'll make another post about some crazy stuff you can do with the media generator. Why oh why? What is an asset manager and why do you need one? Primarily, asset managers are tools for combining and compressing your JS and CSS files into bundles, so instead of many small files your website visitors only need to download a single big JS file and a single big CSS file. This is important because request latency has a much bigger impact on your site's load times than file size. You should definitely read Yahoo's Exceptional Performance and Google's Speed pages to learn more about how to improve your site's performance. The second important task of an asset manager is to help you with handling HTTP caches. This is done by renaming … -
Дизайн API Я.ру
Вчера мы открыли в бету API для Я.ру. Это был первый пост в корпоративном блоге Яндекса с кодом на Питоне, что даже породило фан-арт :-). Для меня этот запуск имеет большое эмоциональное значение, потому что машиночитаемый веб -- мой давний интерес, и этот проект -- первый неигрушечный публичный API, где я занимаюсь дизайном, и могу смотреть, как выживают на практике теоретические соображения о том, как это должно делаться. Я говорю тут от своего лица, и чтобы не возникало ложных ощущений, должен сказать, что я это всё делаю, конечно, не один. Начинал писать собственно серверную часть Иван Челюбеев. Моя текущая роль -- проектировщик и менеджер. Код пишет сейчас Костя Меренков, а со стороны Я.рушного бэкенда нам помогает Серёжа Чистович. Этот пост -- несколько заметок о том, как всё устроено внутри. Пишите в комментариях, если что-то нужно раскрыть подробнее. Сервис над сервисом Сам Я.ру -- многоуровневая кодобаза на нескольких языках и технологиях. Серверная её часть общается с внешним для себя миром по CORBA, и поэтому не подходит для публичного API. Кроме того, публичное API поддерживать тяжелее, чем внутреннее, из-за необходимости думать про обратную совместимость. Поэтому API сервиса Я.ру -- это по сути ещё один отдельный сервис, который смотрит во внешний мир через … -
A Pie... Er, API!
Source: Paul Smith (http://www.flickr.com/photos/psmith/2190712270/) It's no secret that we love data and open information. Forkinit has had an easy way to export your recipes since launch but that's not enough for us. So starting today, Forkinit has it's own API (application programming interface - a way to get raw data out of Forkinit). What we've got now is rough, very 1.0. It's read-only but open to everyone. So if you like code, you might try playing around with the following links: http://forkinit.com/api/v1/recipes/daniel/?format=json http://forkinit.com/api/v1/users/daniel/?format=json http://forkinit.com/api/v1/tags/vegan/?format=json We have plans to further open up the data access and add some more endpoints. If you've got feedback, we'd love to hear it! -
Creating your own Digg/Facebook/Tweetmeme button
This quick walkthrough is going to bring you up to speed on how to create your own social bookmarking button. The three prime examples are the famous Digg button, Facebook’s like functionality and the tweetmeme button. For an implementation look slightly above this paragraph or check out mashable’s version on the left of their post. Our button will be focusing on Fashiolista.com. Fashiolista is a social bookmarking site for fashion, which has seen rapid growth after launching at the next web. This tutorial explains the javascript (client side) aspects of the button. Feedback and improvements on the code would be greatly appreciated. You can find the full 450 lines of js on github. This is what the end result looks like: Compact Medium Large Love it! Love it! Love it! (If you are working on a shop in the fashion industry have a look at our installation instuctions.) Step 1 – The markup Its important to get the client side markup of the button right. Since other sites will be implementing this there is no way you can change it later on. The three major players each have their own way. Facebook XFBML: Async script with XFBML or Iframe Digg … -
man tar
man tar: The GNU folks, in general, abhor man pages, and create info documents instead. Unfortunately, the info document describing tar is licensed under the GFDL with invariant cover texts, which makes it impossible to include any text from that document in this man page. Most of the text in this document was automatically extracted from the usage text in the source. It may not completely describe all features of the program. -
Quick And Easy Execution Speed Testing
There have been many times when I've been programming, encounter a problem that probably involves a loop of some sort, and I think of two or more possible ways to achieve the same end result. At this point, I usually think about which one will probably be the fastest solution (execution-wise) while still being readable/maintainable. A lot of the time, the essentials of the problem can be tested in a few short lines of code. A while back, I was perusing some Stack Overflow questions for work, and I stumbled upon what I consider one of the many hidden jewels in Python: the timeit module. Given a bit of code, this little guy will handle executing it in several loops and giving you the best time out of three trials (you can ask it to do more than 3 runs if you want). Once it completes its test, it will offer some very clean and useful output. For example, today I encountered a piece of code that was making a comma-separated list of an arbitrary number of "%s". The code I saw essentially looked like this: ",".join(["%s"] * 50000) Even though this code required no optimization, I thought, "Hey, that's …