Django community: Community blog posts RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Fashiolista in NY
The Fashiolista team is in New York for the fashion week. I’m looking forward to meet some local tech startups. Drop me a mail or leave a comment if you want to grab a coffee. Cheers, Thierry Schellenbach CTO/ Founder Fashiolista Share and Enjoy: -
Django for beginners
Hello, This is my first blog post and I want to dedicate this to all those web developers out there , who want to move to django for backend developement. This post contains details of installing django and setting up the basic settings to get started with. For all those who are wondering what is django, please look up here. Prerequisites : 1) This post contains the details of installing django on a linux machine. For windows and mac users, the installation procedure might slightly vary. However the setting up of django settings, once the installation is done remains the same. 2) The post is written with the assumption that the user is familiar with basic python. For tutorials on python, please look up here. Installation Procedure: Now that we are done with the talking lets get our hands wet. To install django, download the tarball of the official release here . Please make sure you download the official release from the link in topic 1 of the page mentioned above. Once the tar is downloaded, extract it to a suitable folder of you choice. In my example , I am extracting it to /home/abinav. To extract the tarbal, run … -
The right way not to do things
The right way not to do things -
Release 0.6.6
We just released LFS 0.6.6. This is a yet another bugfix release. Changes Bugfix: fixed url for Pages at breadcrumbs (Maciej Wisniowski) Bugfix: display sale price at category products page (Maciej Wisniowski) Bugfix: fix product pagination (Maciej Wisniowski) Bugfix: added short_description to category management UI Bugfix: display category descriptions Bugfix: fixed template selection; issue #134 Improvement: allow easy modification of category/product templates (Maciej Wisniowski) Updated polish translations (Maciej Wisniowski) News: We have setup a GitHub mirror of LFS. The docs are running on our own domain now (still hosted on RTD) and have a new layout: http://docs.getlfs.com/ Information You can find more information and help on following locations: Documentation on PyPI Demo Releases on PyPI Source code on bitbucket.org and github. Google Group lfsproject on Twitter IRC -
How to Prevent Memory Bloat in Mongo
Feed Mongo!! Several months ago at Yipit, we decided to cross the NoSQL rubicon and port a large portion of our data storage from MySQL over to MongoDB. One of the main drivers behind our move to Mongo was the composition of our data (namely, our recommendation engine system) which consists of loosely structured, denormalized objects best represented as a JSON-style documents. Here’s an example of a typical recommendation object. How Key Expansion Cause Memory Bloat Because any given recommendation can have a number of arbitrary nested attributes, Mongo’s “schemaless” style is much preferred to the fixed schema approach imposed by a relational database. The downside here, though, is that this structure produces extreme data duplication. Whereas a MySQL column is stored only once for a given table, an equivalent JSON attribute is repeated for each document in a collection. Why Memory Management in Mongo is Crucial When your data set is sufficiently small, this redundancy is usually acceptable; however, once you begin to scale up, it becomes less palatable. At Yipit, an average key size of 100 Bytes per document, spread over roughly 65 million documents, adds somewhere between 7GB-10GB of data (factoring in indexes) without providing much value … -
Mock testing long polling
-
An awesome engineer makes me scratch my head
I know an awesome software engineer. He’s very smart and a joy to work with. He’s platinum-grade material, and I’d work with him again in a femtosecond. On rare occasions, this Pythonista among Pythonistas and Djangonaut among Djangonauts writes code that makes me scratch my head. He’ll do this: @classmethod def _clean_field(cls, data, field): """Simple cleaning.""" return data.get(field, '').strip() def clean_series_code(self): """Clean series code.""" return self._clean_field(self.cleaned_data, self.FORM_FIELDS.SERIES_CODE) def clean_oan(self): """Clean OAN.""" return self._clean_field(self.cleaned_data, self.FORM_FIELDS.OAN).replace(',', '') def clean_grant_number(self): """Clean grant number.""" return self._clean_field(self.cleaned_data, self.FORM_FIELDS.GRANT_NUMBER).replace(',', '') def clean_publication_number(self): """Clean publication number.""" return self._clean_field(self.cleaned_data, self.FORM_FIELDS.PUBLICATION_NUMBER) The one-line function that only does a strip() makes my eyeballs itch. I would’ve forgone the _clean_field method: def clean_series_code(self): """Clean series code.""" return self.cleaned_data.get(self.FORM_FIELDS.SERIES_CODE, '').strip() def clean_oan(self): """Clean OAN.""" return self.cleaned_data.get(self.FORM_FIELDS.OAN, '').replace(',', '').strip() def clean_grant_number(self): """Clean grant number.""" return self.cleaned_data.get(self.FORM_FIELDS.GRANT_NUMBER, '').replace(',', '').strip() def clean_publication_number(self): """Clean publication number.""" return self.cleaned_data.get(self.FORM_FIELDS.PUBLICATION_NUMBER, '').strip() It’s understandable that he wanted to abstract how the data was cleaned. But I would argue that strip() is sufficiently innocuous and clear. And _clean_field is one more reason for my eyeballs to have to move on the page. If my eyeballs have to move, I’d like them to receive a better reward than finding a function … -
Getting Django working with MSSQL / pyodbc
Some projects require a MSSQL database (either legacy or for other reasons). Unfortunately Django doesn’t officially support this database (yet). In this tutorial we will show how to connect to MSSQL from Python/Django using pyodbc. Installing on Mac OS X First of all we must install two dependencies: freetds and libiodbc. Let’s use MacPorts for this (http://www.macports.org/). The MacPorts Project is an open-source community initiative to design an easy-to-use system for compiling, installing, and upgrading either command-line, X11 or Aqua based open-source software on the Mac OS X operating system. sudo port install freetds sudo port install libiodbc Now we have to install pyodbc and django-pyodbc (in your virtualenv of course!) pip install pyodbc pip install svn+http://django-pyodbc.googlecode.com/svn/trunk/#django-pyodbc When everything is ready we can set up odbc. To do this open ODBC Manager -> Drivers -> Add… and enter this data (change path if needed): Driver Name: FreeTDS Driver file: /opt/local/var/macports/software/freetds/0.82_0/opt/local/lib/libtdsodbc.so It appears as if the system stores ODBC configuration data in /Library/ODBC, but the Mac Ports stores configuration in /opt/local/etc. So lets do some symlinks: sudo ln -s /Library/ODBC/odbc.ini /opt/local/etc/odbc.ini sudo ln -s /Library/ODBC/odbcinst.ini /opt/local/etc/odbcinst.ini That’s it! Installing on Ubuntu First of all we must install two dependencies: freetds and … -
Async Raven/Sentry client with Django/Python
How to do logging calls to Sentry asynchronously (until Sentry gets UDP support). -
Django Projects and Mercurial Subrepositories
A while back, Steve Losh posted some excellent Django advice, in particular the part on working with third-party apps. I thought it sounded interesting but was concerned that it would be a hassle to maintain. Once I finally tried it, it was quite liberating. Never again will I have to work around some issue with a package. Now I just fix it and move on. It did take a bit of work, though, to figure out an approach that I was happy with. I usually use a pip requirements file to keep track of project dependencies and I wasn't quite sure how to make it all work together. One option is to use pip's editable flag like so: # requirements.txt -e hg+https://bitbucket.org/andrewgodwin/south@64fdcc52cd010e663b7a8b9ad592d4aa204807a2#egg=South-dev What I didn't like about that was having to constantly update my requirements.txt to change the revision. And, by default, pip installs editable packages into $VIRTUAL_ENV/src while I'd rather they be in a subdirectory of my project for easy access. My first attempt at dealing with those issues was to fork every single package I was using, add a tag or branch for the revision my project was using and change the requirements.txt file to look like so: … -
Django Projects and Mercurial Subrepositories
A while back, Steve Losh posted some excellent Django advice, in particular the part on working with third-party apps. I thought it sounded interesting but was concerned that it would be a hassle to maintain. Once I finally tried it, it was quite liberating. Never again will I have to work around some issue with a package. Now I just fix it and move on. It did take a bit of work, though, to figure out an approach that I was happy with. I usually use a pip requirements file to keep track of project dependencies and I wasn’t quite sure how to make it all work together. One option is to use pip’s editable flag like so: requirements.txt1 -e hg+https://bitbucket.org/andrewgodwin/south@64fdcc52cd010e663b7a8b9ad592d4aa204807a2#egg=South-dev What I didn’t like about that was having to constantly update my requirements.txt to change the revision. And, by default, pip installs editable packages into $VIRTUAL_ENV/src while I’d rather they be in a subdirectory of my project for easy access. My first attempt at dealing with those issues was to fork every single package I was using, add a tag or branch for the revision my project was using and change the requirements.txt file to look like so: requirements.txt1 … -
Pre-validating Many to Many fields.
Django's form validation is great. You can rely on it to parse data that you got from the user, and ensure that the rules you have implemented are all applied. Model validation is similar, and I tend to use that in preference, as I often make changes from outside of the request-response cycle. Indeed, I've started to rewrite my API framework around using forms for serialisation as well as parsing. One aspect of validation that is a little hard to grok is changes to many-to-many fields. For instance, the part of the system I am working on right now has `Tag`s that are applied to `Unit`s, but a change to business requirements is that these tags need to be grouped, and a unit may only have one tag from a given `TagGroup`. Preventing units from being saved with an invalid combination of Tags is simple if you use the `django.db.models.signals.m2m_changed` signal. {% highlight python %} from django.db.models.signals import m2m_changed from django.dispatch import receiver @receiver(m2m_changed, sender=Tag.units.through) def prevent_duplicate_tags_from_group(sender, instance, action, reverse, model, pk_set, **kwargs): if action != 'pre_add': return if reverse: # At this point, we know we are adding Tags to a Unit. tags = Tag.objects.filter(pk__in=pk_set).select_related('group') existing_groups = TagGroup.objects.filter(tags__units=instance).distinct() invalid_tags … -
Apple lion reinstall experience and surprise
-
Evennia's open bottlenecks
Since Evennia hit beta I have been mostly looking behind the scenes to see what can be cleaned up and not in the core server. One way to do that is to check where the bottlenecks are. Since a few commits, Evennia's runner has additions for launching the Python cProfiler at startup. This can be done for both the Portal and the Server separately.I have created a test runner (soon to hit trunk) that launches dummy clients. They log on and then goes about their way executing commands, creating objects and so on. The result of looking at the profiling data (using e.g. runsnake) has been very interesting.Firstly, a comparably small part of execution time is actually spent in Evennia modules - most is spent using Python built-ins and in the Twisted/Django libraries. This is promising in a way - at least there are no expensive loops in the Evennia code itself that sucks up cycles. Of course it also means we depend heavily on django/twisted (no surprise there) and especially when it comes to database access, I know there could be more caching going on so as to cut down on db calls. Of the Evennia modules, a lot of time is … -
About this dev blog
This is to be my Evennia dev blog, but it will also cover various other musings concerning programming in general and mud designing in particular. Whereas the Evennia mailing list remains the main venue for discussion, I will probably use this blog for announcing features too.Some background: Evennia is a Python MUD/MUX/MU* server. More correct is probably to call it a "MUD-building system". The developer codes their entire game using normal Python modules. All development is done with the full power of Python - gritty stuff like database operations and network communication are hidden away behind custom classes that you can treat and modify mostly like any Python primitives.Since the server is based on the Twisted and Django technologies we can offer many modern features out of the box. Evennia is for example its own web server and comes with both its own website and an "comet"-style browser mud client. But before this turns into even more of a sales pitch, I'll just just direct you to the evennia website if you want to know more. :) I, Griatch, took over the development of Evennia from the original author, Greg Taylor, in 2010. -
Configuring application settings for a Django project
Configuring application settings for a Django project -
Release 0.6.5
We just released LFS 0.6.5. This is a yet another bugfix release. Changes Bugfix: added csrftoken for rating mails (Maciej Wisniowski) Bugfix: fixed ImageWithThumbsField (Maciej Wisniowski) Updated romanian translations (olimpiu) Updated polish translations (Maciej Wisniowski) News: We have setup a GitHub mirror of LFS. The docs are running on our own domain now (still hosted on RTD) and have a new layout: http://docs.getlfs.com/ Information You can find more information and help on following locations: Documentation on PyPI Demo Releases on PyPI Source code on bitbucket.org and github. Google Group lfsproject on Twitter IRC -
HTTP Status Codes Site
During the development of Simple Site Checker I realised that it would be useful for test purposes if there is a website returning all possible HTTP status codes. Thanks to Google App Engine and webapp2 framework building such website was a piece of cake. The site can be found at http://httpstatuscodes.appspot.com. The home page provides [...] -
Modular django settings
A recurring feature of [#django][#django] is that someone asks about `settings.py`, and using a `local_settings.py` file. The standard advice is to have the following in your `settings.py`: {% highlight python %} # More settings are above here. try: from local_settings import * except ImportError: pass {% endhighlight %} This is usually the last (or one of the last) things in the file. This can be used to override settings with sane values for the local environment. However, this means that `local_settings.py` must be not in your source control system, or must not be deployed to other servers. I like keeping everything in my source control system of choice (mercurial), and currently use an hg-based deployment. In my `fabfile.py`, instead of archiving up the current structure, I use `hg` to push the main repo, and any sub-repos, and update them to the version that is displayed locally. This means I want to be able to control the content of production's `local_settings.py` equivalent. The other issue, and this was the one that came up today and gave me the idea of this post, is that someone wanted to add an app to `settings.INSTALLED_APPS` but only locally. I too have done this (still … -
Facebook open graph publishing simplified
Facebook has just enabled the open graph for 60 lucky apps. The new open graph beta allows you to post a user’s actions to their timeline. This activity is shown to the user’s friends in Facebook’s newsfeed and ticker. Furthermore your data is nicely aggregated on a user’s Facebook profile. Fashiolista’s aggregation for instance looks like this: Posting these actions on Facebook can greatly enhance the viral growth of your company. Spotify, one of the launch partners, has grown by more than 4mil active users. This blogpost explains how to use Django Facebook to integrate your Django based site with Facebook. How open graph works Before going into the code though we need to understand the basic concepts of the open graph: actions and objects. Facebook’s getting started interface explains it best: Actions are the verb, objects are what the action is applied to. You submit the data for these actions and objects to Facebook. An example would be watching (action) the movie Pan’s Labyrinth (object). Every object should be represented by a dedicated URL. For instance if you look at Chiara’s profile (object) on Fashiolista you will see the following open graph data: <meta property="og:title" content="ChiaraFerragni" /> <meta property="og:image" … -
django-cms 2.0.2 and Django 1.2 – 1.3
If you are running an old version of django-cms, you can still upgrade Django. I would strongly suggest doing this since it’s very uncomplicated. However, if you are running django-cms 2.0, you should first upgrade to 2.0.2 and run the South migrations, which is also totally uncomplicated. django-cms 1.x are most likely stuck on older versions of Django as well. I did once try to get them running on new Django versions but gave up. Basically this guide just fixes a little bug in admin/pageadmin.py and a few issues regarding a missing csrf_token in the templates. It also means that django-cms 2.0.2 becomes SSL compatible. This is not backwards-compatible, however, so if you apply this stuff, your django-cms will no longer work with Django 1.1. After upgrading to django 1.3.1 (also tested on 1.2.X btw), you need to make the following corrections manually in your django-cms installation. 1) Edit cms/admin/pageadmin.py, line 59 to say: exclude = [] 2) Edit cms/templates/admin/cms/page/plugin_change_form.html, line 77, by adding the csrf_token tag: <form id="{{ opts.module_name }}_form" action="{{ form_url }}" method="post" enctype="multipart/form-data">{% block form_top %}{% endblock %} {% csrf_token %} 2.1) Do the same in cms/templates/admin/cms/page/change_form.html, line 99: <form id="page_form" action="?language={{ language }}{%if request.GET.target %}&amp;target={{ request.GET.target … -
Forms Part 4: Formsets
Formsets make life easier when it comes to dealing with multiple forms of the same type on the same page. In this episode we will show you how to set them up, and the basics of how to save that data to the database. It is not much different from dealing with single forms. Watch Now... -
Forms Part 4: Formsets
Formsets make life easier when it comes to dealing with multiple forms of the same type on the same page. In this episode we will show you how to set them up, and the basics of how to save that data to the database. It is not much different from dealing with single forms. Watch Now... -
Dajaxproject, primera part
Una de les preguntes més recurrents en les llistes de Django, junt amb la de quin editor fer servir és la de com fer cridades AJAX i quina llibreria utilitzar. Django és agnòstic en el que fa a les llibreries javascript, tot i això la part de l'admin fa servir jQuery, però oficialment no hi ha cap llibreria especialment recomanada, Django és pot utilitzar amb qualsevol llibreria i dependrà del projecte que en triem una o altra. El problema de que no es faci cap recomanació de com integrar cridades AJAX amb Django ens dóna molta llibertat, però també te l'emperò de que no hi ha cap guia de bones pràctiques sobre com fer-ho, des d'on posar la llibreria, quin nom li hem de donar, si la posam al views.py o no. El la comunitat de codi obert quan hi ha un buid així i una necessitat ben aviat sorgeixen projectes que intenten donar una resposta. Un d'aquests projectes és el que us present en aquest article el dajaxproject. Djaxaproject són de fet dues llibreries, dajaxice i dajax, la primera podríem dir que respon a la necessitat que us comentava de fer més senzilla la comunicació asíncrona entre les aplicacions … -
Simple Site Checker
… a command line tool to monitor your sitemap links I was thinking to make such tool for a while and fortunately I found some time so here it is. Simple Site Checker is a command line tool that allows you to run a check over the links in you XML sitemap. How it works: [...]