Django community: Community blog posts RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Django and IPython Notebook
Django and IPython Notebook -
Postgres VIEW meet Django Model
[Postgres](http://www.postgresql.org) `VIEW`s are a nice way to store a subset of a table in a way that can itself be queried, or perhaps slightly or radically changing the shape of your table. It has a fairly simple syntax: {% highlight sql %} CREATE VIEW "foo" AS SELECT "bar", "baz", "qux" FROM "corge" WHERE "grault" IS NULL; {% endhighlight %} You may use any valid `SELECT` query as the source of a `VIEW`, including one that contains `UNION` or `UNION ALL`. You can use this form to create a view that takes two similarly formatted tables and combines them into one logical table. Note that for a `UNION` to work, the columns (and column types) must be identical between the two parts of the query. A `UNION` will do extra work to ensure all rows are unique: `UNION ALL` may perform better, especially if you know your rows will be unique (or you need duplicates). By default, a Postgres `VIEW` is dynamic, and read-only. With the use of the `CREATE MATERIALIZED VIEW` form, it's possible to have a cached copy stored on disk, which requires an `UPDATE MATERIALIZED VIEW "viewname"` in order to cause an update. It's also possible to create … -
Django & Rails - another year another comparison
It is the time of the year where I start talking about Django and Ruby on Rails. Since my last two posts I received many questions about this topic and the old posts are still read frequently and quoted. So let me bring you up to date what changed, what improved since the last post and which framework is the best choice. If you did not read my last two posts about this topic I suggest you read them now. I will make claims and statements in this post I already elaborated in them and without the context they can be quite controversial. To the disappointment of some of you: this is still not Django vs Rails - it is no discussion that will come to the conclusion that there is a holy grail of frameworks, totally destroying one of them with arguments why the other one is so superior. While Django is slowly moving towards migrations being part of the core functionality Ruby on Rails just added support for real foreign keys support. Django 1.7, which will bring you the joy of migrations, is currently not marked as stable, but release candidate two makes a good impression and it … -
Django & Rails - another year another comparison
Django & Rails - another year another comparison It is the time of the year where I start talking about Django and Ruby on Rails. Since my last two posts I received many questions about this topic and the old posts are still read frequently and quoted. So let me bring you up to date what changed, what improved since the last post and which framework is the best choice. If you did not read my last two posts about this topic I suggest you read them now. I will make claims and statements in this post I already elaborated in them and without the context they can be quite controversial. To the disappointment of some of you: this is still not Django vs Rails - it is no discussion that will come to the conclusion that there is a holy grail of frameworks, totally destroying one of them with arguments why the other one is so superior. While Django is slowly moving towards migrations being part of the core functionality Ruby on Rails just added support for real foreign keys support. Django 1.7, which will bring you the joy of migrations, is currently not marked as stable, but release … -
Creating a re-usable Django app - Part 1
Hi everyone and welcome back for this next tutorial of the Babbler series. This tutorial will cover 2 ways of creating a re-usable Django app. The first and simplest one is apps for flexible and personal re-use. The second one is a somewhat less simple way of doing it but which allows re-distribution of your application and that can be a very good thing too! For the first part of this tutorial we will be using the custom user model, built during the previous tutorial, as a starting point. The second part will be using the theme application built during the Using your own flavour of bootstrap with django tutorial. -
Avoiding SQL Antipatterns using Django (and Postgres)
The book [SQL Antipatterns](http://pragprog.com/book/bksqla/sql-antipatterns) is one of my favourite books. I took the opportunity to reread it on a trip to [Xerocon](https://www.xero.com/au/xerocon/sydney/) in Sydney, and as usual it enlightened me to thing I am probably doing in my database interactions. So, I'm going to look at these Antipatterns, and discuss how you can avoid them when using [Django](https://ww.django project.com). This post is intended to be read with each chapter of the book. I've used the section headings, but instead of the chapter headings, I've used the Antipattern headings. They are still in the same order, though. It seems the printed version of this book is on sale now: I'm tempted to buy a few extra copies for gifts. Ahem, cow-orkers. Logical Database Design Antipatterns ¶ Format Comma-Separated Lists ¶ This one is pretty simple: use a relation instead of a [Comma Separated field](https://docs.djangoproject.com/en/1.7/ref/models/fields/#commaseparatedintegerfield). In the cases described in the book, a [`ManyToManyField`](https://docs.djangoproject.com/en/1.7/ref/models/fields/#manytomanyfield) is in fact simpler than a Comma Separated field. Django gets a gold star here, both in ease of use, but also in documentation about relations. However, there may be times when a relation is overkill, and a real array is better. For instance, when storing data related … -
Django Templating Language - Part I
Hey guys! I know I haven't posted anything in a very long time. Exigent circumstances. Anyway, now I'm back with what may well be the most important skill in your entire Django toolkit. The templating language that Django ships makes writing pages that display multiple results mundanely easy.In this part I'll only introduce you to templates. We'll see how to render them in the next one.Variables:We all know what variables are and how important they are for programming. This is how variables are represented in Django:{{ variable_name }}It can also be written as {{variable_name}} but the former is more readable. Let's see how to 'declare' a variable in an HTML script:<h1>{{ heading }}</h1><form action = "/foo/" method = "post"> <input type = "text" name = "bar" placeholder = "{{ placeholder }}"></form>Notice the difference? {{ heading }} is without quotes and {{ placeholder }} is with. The basic concept is you write the name of the variable exactly as you would write normal text. While writing normal text, you would not put quotes between the <h1>...</h1> tags but would in the <input> tag.Right now if you just write this much code it'll print all raw data. There is no use … -
Chaussette and Circus as a new way to deploy your Django applications
Many Python web applications run on production with the help of gunicorn or uwsgi. There are however other solutions that may turn out to be even better than the currently popular solutions. One of alternatives is chaussette and circus. Chaussette is a WSGI server that can serve WSGI applications like your Django project. Circus is an application to control and monitor processes and sockets. It can manage chaussette, celery or other sockets and processes making it a manager of all project services. -
What's New With WhisperGifts
It's been a busy few months for WhisperGifts, my bridal gift registry service built with Django. This post rounds up a few recent additions and changes, including technical details for those who want to do something similar. Highlights include weather forecasting, REST APIs, and JavaScript bookmarklets. -
What's New With WhisperGifts
It's been a busy few months for WhisperGifts, my bridal gift registry service built with Django. This post rounds up a few recent additions and changes, including technical details for those who want to do something similar. Highlights include weather forecasting, REST APIs, and JavaScript bookmarklets. -
What's New With WhisperGifts
In the past couple of months I've done some fun and interesting stuff over at WhisperGifts, my side project that lets couples put their bridal gift registry online. It's all built with Django, so I thought I'd share a few neat things I've come across along the way. Bookmarket and image detection For a while I've had a bookmarklet to add any item to your registry, which basically took the page title, selected text (or meta description), and URL and pre-filled the Add Item form. Recently, I updated it to also find the largest image on the page, and add that as the default image for the item you selected. This makes it pretty quick to add an item from, for example, an Amazon page or a manufacturer's website. The code to do it was surprisingly simple. Apologies for the short variable names; this is taken directly from my bookmarklet code so brevity is a plus in that scenario. var ims=document.getElementsByTagName('img'); var imsMxD=0; var im=''; for(x=0;x<ims.length;x++){ var xDim=parseFloat(ims[x].width)*parseFloat(ims[x].height); if((xDim>imsMxD)&&(ims[x].src)){ imsMxD=xDim; im=ims[x].src; } } This will give me a variable, im, which contains the URL of the largest image on the page. I then pass this to the form to pre-populate … -
What's New With WhisperGifts
In the past couple of months I've done some fun and interesting stuff over at WhisperGifts, my side project that lets couples put their bridal gift registry online. It's all built with Django, so I thought I'd share a few neat things I've come across along the way. Bookmarket and … -
IP Street is hiring! Senior Developer (Python, Django)
Overview Founded in 2010, IP Street has built the world’s preeminent Intellectual Property(IP) analytics and visualization engine, in conjunction with a nationally recognized IP law firm. Our SaaS product helps corporations and financial analysts quickly and efficiently analyze IP information. We make IP data easy to get, use, and understand! As with any organization, we’ve continued to evaluate new ways to provide value to our clients. We’re evolving into a “SaaS+” model, which pairs our service with expert consultation to assist our clients in assessment and evaluation. Our focus remains on the financial and technology markets. Our technology stack is almost all open-source, with some nifty esoteric search technologies. Most of your work will be in Python and Django, in a Mac-based development environment, deploying to Linux. Other technologies include Postgres, Redis, and Solr. Our client-side code relies on Highcharts and Backbone. This is a “small b” big data firm. But since we’re a scrappy start-up, we don’t have a big firm’s resources. We compensate by hiring senior people who are self-directed, appreciate real-world development trade-offs, and have a can-do attitude. It’s OK to not know something if you’re eager and willing to learn it. We know that bad code … -
Django Extensions 1.3.11
We are happy to release: Django-Extensions Version 1.3.11 This brings the usual tons of fixes and improvements Get it at: https://pypi.python.org/pypi/django-extensions/1.3.11 Changes: Improvement: sqldiff, show differences for not managed tables Improvement: show_urls -f aligned, 3 spaces between columns Improvement: reset_db, support mysql options files in reset_db Fix: sqldiff, Fixed bug with --output_text option and notnull-differ text Fix: reset_db, Fix for PostgreSQL databases with dashes, dots, etc in the name Fix: dumpscript, AttributeError for datefields that are None Docs: Adding RUNSERVERPLUS_SERVER_ADDRESS_PORT to docs -
Related ManyToManyField in Django admin site
Hello everyone. There is something quite common people are trying to do in Django which is accessing a ManyToMany relationship from both ends in Django admin. Since this is something I am going to have to explain to someone tomorow, I thought I'd take the opportunity to write a short tutorial about it. -
Liquid Templates and Django Templates
Note to self: when I get the error: {% highlight rbcon %} /Library/Ruby/Gems/1.8/gems/jekyll-0.11.2/bin/../lib/jekyll/convertible.rb:81:in `do_layout': undefined method `name' for # (NoMethodError) from /Library/Ruby/Gems/1.8/gems/jekyll-0.11.2/bin/../lib/jekyll/post.rb:189:in `render' from /Library/Ruby/Gems/1.8/gems/jekyll-0.11.2/bin/../lib/jekyll/site.rb:193:in `render' from /Library/Ruby/Gems/1.8/gems/jekyll-0.11.2/bin/../lib/jekyll/site.rb:192:in `each' from /Library/Ruby/Gems/1.8/gems/jekyll-0.11.2/bin/../lib/jekyll/site.rb:192:in `render' from /Library/Ruby/Gems/1.8/gems/jekyll-0.11.2/bin/../lib/jekyll/site.rb:40:in `_draft_process' from /Users/matt/Dropbox/Blog/_plugins/drafts.rb:15:in `process' from /Library/Ruby/Gems/1.8/gems/jekyll-0.11.2/bin/jekyll:250 from /usr/local/bin/jekyll:19:in `load' from /usr/local/bin/jekyll:19 {% endhighlight %} It's probably because I have used django template tags in the {% raw %}`{% (end)highlight %}`{% endraw %} blocks, and omitted the {% raw %}``{% (end)raw %}``{% endraw %} stuff. -
Leveraging HTML and Django Forms: Pagination of Filtered Results
Django's forms are fantastic for parsing user input, but I've come up with a nice way to use them, in conjunction with HTML forms, for pagination, using the inbuilt Django pagination features. It all stems from the fact that I've begun using forms quite heavily for GET purposes, rather than just for POST. Basically, anytime you have a URL that may have some parts of the query string that may need to be built, it's simpler to use a form element, than to manually build up the url in your template. Thus, where you may have something like: {% highlight html+django %} {% raw %} {% endraw %} {% endhighlight %} It may be better do do something more like: {% highlight html+django %} {% raw %} {% endraw %} {% endhighlight %} Indeed, you can even use named buttons for submission, which will refer to the page. That is the key to the process outlined below. * * * Django comes with lots of "batteries", including form handling and pagination. The Class Based Views (CBV) that deal with collections of objects will include pagination, although it is possible to use this pagination in your own views. For simplicity, we'll … -
Updated repository for the Babbler series
Hi everyone. This is just a short post to let you know that we have updated the repository for the Babbler tutorial series. Instead of using a different repository for each tutorial, we will now be using a single repository accessible from here. Each tutorial has its own branch and tags mark the start and end of each tutorial part. We have also uploaded the code for the last tutorial (Creating a custom user model in Django 1.6) since it was missing. Some time next week we will publish the next tutorial in the series: Creating re-useable apps. In the mean time: happy coding everyone -
My Talk "Django at scale" at Django London Meetup
On Tuesday I gave a talk on Django at the London Django Meetup Group, titled "Django at Scale." Here are my slides: Here are a few brief summaries of topics I covered, which I hope to cover in more depth with a blog post on each in the future: 1. Wrap Django's Classes For Your Project Sub-classing django's base classes, e.g. the Admin classes as in for, allows you to make whole codebase changes easily. It's not that much effort to implement and allows you to solve many problems easily. It's also an argument for class-based views. I've give a complete example of doing this in my post on extending querysets and the admin to return approximate counts. 2. Background-fill Your Cache The most common cache pattern for django is to test if the item is in the cache, and if it's not there, to run the slow function to generate it. Often this is a user dependent variable, e.g. the count of all the comments they've made. When you expand to a certain scale though, you're sure to see a user for whom this slow function takes just way too long no matter what. You can notice this by … -
My Talk "Django at scale" at Django London Meetup
On Tuesday I gave a talk on Django at the London Django Meetup Group, titled "Django at Scale." Here are my slides: Here are a few brief summaries of topics I covered, which I hope to cover in more depth with a blog post on each in the future: 1. Wrap Django's Classes For Your Project Sub-classing django's base classes, e.g. the Admin classes as in for, allows you to make whole codebase changes easily. It's not that much effort to implement and allows you to solve many problems easily. It's also an argument for class-based views. I've give a complete example of doing this in my post on extending querysets and the admin to return approximate counts. 2. Background-fill Your Cache The most common cache pattern for django is to test if the item is in the cache, and if it's not there, to run the slow function to generate it. Often this is a user dependent variable, e.g. the count of all the comments they've made. When you expand to a certain scale though, you're sure to see a user for whom this slow function takes just way too long no matter what. You can notice this by … -
My Talk "Django at scale" at Django London Meetup
On Tuesday I gave a talk on Django at the London Django Meetup Group, titled “Django at Scale.” Here are my slides: Here are a few brief summaries of topics I covered, which I hope to cover in more depth with a blog post on each in the future: 1. Wrap Django’s Classes For Your Project Sub-classing django’s base classes, e.g. the Admin classes as in for, allows you to make whole codebase changes easily. It’s not that much effort to implement and allows you to solve many problems easily. It’s also an argument for class-based views. I’ve give a complete example of doing this in my post on extending querysets and the admin to return approximate counts. 2. Background-fill Your Cache The most common cache pattern for django is to test if the item is in the cache, and if it’s not there, to run the slow function to generate it. Often this is a user dependent variable, e.g. the count of all the comments they’ve made. When you expand to a certain scale though, you’re sure to see a user for whom this slow function takes just way too long no matter what. You can notice this by … -
DjangoCon 2014 Ticket Giveaway
Caktus is giving away a DjangoCon ticket valued at $850. DjangoCon is the main US Django conference and it’s returning to Portland this year, August 30 - September 4th. Meet fellow Django developers, learn what others are doing, and have a good time! To enter the giveaway, (1) follow us @caktusgroupand and (2) retweet our message by clicking the button below: Tweet The giveaway will end Wednesday, August 20th at 9AM PDT. We’ll randomly select a name and alert the winner by 5PM PDT. Please note that only one entry per individual is allowed and winning tickets are non-transferable. We hope to see you at DjangoCon this year! -
Hola, Argentina!
I'll be arriving in Argentina on August 14th. I'll be speaking at PyDay Mendoza on August 15th, and sprinting on August 16th on something Audrey and I named the "new library sprint" (more details to come). On August 22nd, I'll be speaking at the combined Buenos Aires Python, Django, and PyLadies Argentina meetup. Between the events I'll be working from the _Eventbrite / _Eventioz Argentina office. I'm extremely excited. I've wanted to go to Argentina for years. It's a beautiful country filled with magnificent culture, lovely architecture, great food, superb wine, and wonderful people. Speaking of which, I can't wait to finally put faces to people I've gotten to know over the internet. Hasta pronto! -
Hola, Argentina!
I'll be arriving in Argentina on August 14th. I'll be speaking at PyDay Mendoza on August 15th, and sprinting on August 16th on something Audrey and I named the "new library sprint" (more details to come). On August 22nd, I'll be speaking at the combined Buenos Aires Python, Django, and PyLadies Argentina meetup. Between the events I'll be working from the Eventbrite/Eventioz Argentina office. I'm extremely excited. I've wanted to go to Argentina for years. It's a beautiful country filled with magnificent culture, lovely architecture, great food, superb wine, and wonderful people. Speaking of which, I can't wait to finally put faces to people I've gotten to know over the internet. Hasta pronto! -
Review: Django Essentials
A month ago Dyson D'Souza from PacktPub approached me asking if I would be interested in reviewing Django Essentials. I am using Django for some time now - somewhen pre 0.96, I remember the 0.96 release for some reason, I think it was the length of the release cycle but I am not sure anymore - and I really wanted to see how the introduction resources changed, so this was a good chance. Samuel Dauzon does a really good job writing for people who are just starting to work with Django. Beside some history he manages to explain all important concepts and, this is something I especially like, transports them to the terminology used by Django. After explaining what MVC is he also explains what Django is calling the different parts and how they fit together. This is something I often missed when reading a blog post or skimming through another book. While it is a good introduction you should already now a little bit of Python to feel comfortable. The book is suggesting Python 3 which is in my opinion still a risky route to take for a beginner. While most libraries are ported you can still easily run …