Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Python Programmers Support the Ada Initiative
Please join me in helping making the Python community better by supporting the Ada Initiative. Last year, the Python community raised $10,000 for the Ada Initiative. This year I am betting we can beat that record and raise $20,000! Carl Meyer, Alex Gaynor, Jim Meyer, and I are pledging to match up to $10,000 in donations from the Python community; please join us in donating! Update: Minutes after we annonunced this, Jim Meyer offered an additional $2,500, bringing the match total to $10,000! -
On Flying Starts
What a start for a blog to end up on the homepage of Hacker News on the first day (with a <a title="Django UI in 2005 vs Django UI in 2014" href="/en/hoyci/2014/09/django-2005-2014/">short post about Django UI</a>). The good: it's surprisingly easy to install a cache plugin to Wordpress. The bad: this blog is not hosted on the Slipmat.io server (because I don't want to install PHP on it) so I missed a great chance to stress-test it.<img class="aligncenter size-full" src="https://www.unessa.net/static/kuvat/hoyci/screen-shot-2014-09-18-at-183557.png" alt="254 Concurrent Users in Google Realtime Analytics" /> To stay with the topic on flying starts, I've been quietly readying the first Slipmat.io tool, a site for taking and making requests in Mixify events, for its official launch. I opened the site for public three weeks ago and I've been working on it ever since. I'm keeping <a href="http://slipmat.io/requests/about/release_notes/">detailed public release notes</a> to keep the users updated and also for myself as a way to get a feel of the progress. Most non-DJs and furthermore non-Mixify users probably have no idea what this tool actually does, so <strong>let me explain it quickly</strong>. <a href="http://www.mixify.com/">Mixify</a> is a Web site where DJs can play for a live audience by streaming sound (and … -
Ramblings about data-structures
I was reading this the other day. The article presents this peculiar quote: "It is better to have 100 functions operate on one data structure than to have 10 functions operate on 10 data structures." —Alan J. Perlis [1] And then some thoughts and questions regarding the quote that seemed a bit ridiculous. But what does this seemingly ambiguous quote really mean ? After some thought, I've concluded that it's an apologia for Lisp's lists everywhere philosophy. You can reduce the quote to: It's better to have one extremely generic type than 10 incompatible types. Python already does this: every object implements, surprise, an object interface that boils down to a bunch of magic methods. On the other hand, Lisp has generic functions. What this mean is that there is a dispatch system that binds certain function implementations to certain data-structures. A data structure that is bound with specific actions (aka functions or methods) is what I call a type. The idea of not having specialised data-structures is an illusion - if a function takes something as an input then you have assumed a specific data structure, not just a mere list. This is why I think it's worthwhile designing the … -
Ramblings about data-structures
I was reading this the other day. The article presents this peculiar quote: "It is better to have 100 functions operate on one data structure than to have 10 functions operate on 10 data structures." —Alan J. Perlis [1] And then some thoughts and questions regarding the quote that seemed a bit ridiculous. But what does this seemingly ambiguous quote really mean? After some thought, I've concluded that it's an apologia for Lisp's lists everywhere philosophy. You can reduce the quote to: It's better to have one extremely generic type than 10 incompatible types. Python already does this: every object implements, surprise, an object interface that boils down to a bunch of magic methods. On the other hand, Lisp has generic functions. What this mean is that there is a dispatch system that binds certain function implementations to certain data-structures. A data structure that is bound with specific actions (aka functions or methods) is what I call a type. The idea of not having specialised data-structures is an illusion - if a function takes something as an input then you have assumed a specific data structure, not just a mere list. This is why I think it's worthwhile designing the data-structures … -
Ramblings about data-structures
I was reading this the other day. The article presents this peculiar quote: "It is better to have 100 functions operate on one data structure than to have 10 functions operate on 10 data structures." —Alan J. Perlis [1] And then some thoughts and questions regarding the quote that seemed a bit ridiculous. But what does this seemingly ambiguous quote really mean? After some thought, I've concluded that it's an apologia for Lisp's lists everywhere philosophy. You can reduce the quote to: It's better to have one extremely generic type than 10 incompatible types. Python already does this: every object implements, surprise, an object interface that boils down to a bunch of magic methods. On the other hand, Lisp has generic functions. What this mean is that there is a dispatch system that binds certain function implementations to certain data-structures. A data structure that is bound with specific actions (aka functions or methods) is what I call a type. The idea of not having specialised data-structures is an illusion - if a function takes something as an input then you have assumed a specific data structure, not just a mere list. This is why I think it's worthwhile designing the … -
Ramblings about data-structures
I was reading this the other day. The article presents this peculiar quote: "It is better to have 100 functions operate on one data structure than to have 10 functions operate on 10 data structures." —Alan J. Perlis [1] And then some thoughts and questions regarding the quote that seemed a bit ridiculous. But what does this seemingly ambiguous quote really mean? After some thought, I've concluded that it's an apologia for Lisp's lists everywhere philosophy. You can reduce the quote to: It's better to have one extremely generic type than 10 incompatible types. Python already does this: every object implements, surprise, an object interface that boils down to a bunch of magic methods. On the other hand, Lisp has generic functions. What this mean is that there is a dispatch system that binds certain function implementations to certain data-structures. A data structure that is bound with specific actions (aka functions or methods) is what I call a type. The idea of not having specialised data-structures is an illusion - if a function takes something as an input then you have assumed a specific data structure, not just a mere list. This is why I think it's worthwhile designing the data-structures … -
Django 1.7 新数据迁移工具 (migrations) 的使用和如何从 South 升级转换
在1.6之前, Django只支持添加新的model到数据库, 而无法编辑或修改已经存在的model. 在当时, 这些Django缺失的功能可以通过South实现. 1. 新的命令 Django 1.7 为我们带来了三个新命令: migrate: 用于执行迁移动作 makemigrations: 基于当前的model创建新的迁移策略文件 sqlmigrate: 显示迁移的SQL语句 值得注意的是, migration是基于App的, 因此, 我们可以针对某些app不启用migration功能. 2. 如何使用 migrations的使用非常简单: 修改model, 比如增加field, 然后运行 python manager.py makemigrations 你的mmodel会被扫描, 然后与之前的版本作比较, 在app的migrations目录下生成本次迁移文件. 我们建议查看一下该迁移文件, 确保没有问题. 然后运行: python manager.py migrate migrate命令会进行比较, 并应用该迁移. 3. 从South到新的Django migrations 如果想从south升级到最新的django migration, 可以按以下步骤实现: 确保south中的migration全部被应用了 从 INSTALLED_APPS中移除south 删除每个app下migration目录中的所有文件, 除了__init__.py 运行python manager.py makemigrations, Django会初始化migration 运行python manager.py migrate, django会发现数据库和初始化的migration相同, 从而将他们标记为已应用 -
Django UI in 2005 vs Django UI in 2014
I stumbled across my favourite ever tech talk, <a href="https://www.youtube.com/watch?v=cb9KDt9aXc8">the legendary Snakes and Rubies event</a> where Django met Rails, back in 2005. One thing caught my eye while re-watching every minute of the 3-hour event: the Django Web site and the Admin Site app look almost <em>exactly</em> the same today than they did 9 years ago. <img class="aligncenter size-full" src="/static/kuvat/hoyci/screen-shot-2014-09-17-at-225740.png" alt="Screen capture image from Djangoproject.com as it was in 2005" /> <p style="text-align: center;"><em>Still image of Djangoproject.com from the Snakes and Rubies video, 2005.</em></p> <p>&nbsp;<p> <p style="text-align: center;"><img class="aligncenter size-full" src="/static/kuvat/hoyci/screen-shot-2014-09-17-at-225028-1024x559.png" alt="Screen Shot 2014-09-17 at 22.50.28" /></p> <p style="text-align: center;"><em>Djangoproject.com, 2014.</em></p> <p>&nbsp;<p> <p style="text-align: center;"><img class="aligncenter size-full" src="/static/kuvat/hoyci/screen-shot-2014-09-17-at-225247.png" alt="Still image from Snakes and Rubies video" /></p> <p style="text-align: center;"><em>Still image of Django Admin Site from the Snakes and Rubies video, 2005.</em></p> <p>&nbsp;<p> <p style="text-align: center;"><img class="aligncenter size-full" src="/static/kuvat/hoyci/screen-shot-2014-09-17-at-225844.png" alt="Screen Shot 2014-09-17 at 22.58.44" /></p> <p style="text-align: center;"><em>A screencapture of one Django Admin app (in Finnish -- it still talks also Welsh, among others), 2014.</em></p> <p>&nbsp;<p> <p>I don't want to comment this in any other way but to notice that it's quite amazing that Djangoproject.com still looks so good and I actually <em>like</em> using it every single day -- it works … -
My take on the "12 factor app"
http://12factor.net/ is often quoted as a standard shopping list if you want to get your deployment right. At least in the Python web world it is, it seems to me. I'm currently looking at the way we deploy stuff at our company (Nelen & Schuurmans). Partially by hand, lots via fabic, increasing use of ansible. And many infrastructure-parts like the main web proxy config essentially by hand, aided by scripts. Not everything in the 12 factor app list is needed for us, but it helps me think about what we need to keep and what we need to improve. One codebase tracked in revision control, many deploys. We use git/github well. We also have multiple deploys, this works OK. Explicitly declare and isolate dependencies. Python packages and buildout. Pinning. Works fine. A few projects are less tidy, though, with git branch checkouts instead of tidy packages. Take care with javascript/css dependencies. The recent trend towards grunt, bower and so with a nice requirements file: looks good. On the whole, the way we compose the actual project works fine. Store config in the environment. DATABASES out of settings.py. We do this wrong now. Environment settings or, perhaps better, configuration in an … -
Adding Django form instance attributes
Sometimes in the clean(), clean_FOO or save() methods of a Django form, you need to have additional form instance attributes available. A sample case for this is having user_id available. This is a simple example of how to do it in Class-Based Views. Assuming this form: from django import forms from .models import MyModel class MyForm(forms.ModelForm): class Meta: model = MyModel def __init__(self, user_id, *args, **kwargs): super(MyForm, self).__init__(*args, **kwargs) # set the user_id as an attribute of the form self.user_id = user_id Now that the form is defined, the view needs to inject the form with the user id: from django.views.generic import UpdateView # this assumes that django-braces is installed from braces.views import LoginRequiredMixin from .forms import MyForm from .models import MyModel class MyUpdateView(LoginRequiredMixin, UpdateView): model = MyModel form_class = MyForm success_url = "/someplace/" def get_form_kwargs(self): """This method is what injects forms with their keyword arguments.""" # grab the current set of form #kwargs kwargs = super(MyUpdateView, self).get_form_kwargs() # Update the kwargs with the user_id kwargs['user_id'] = self.request.user.pk return kwargs Additional Notes You can use this technique with: forms.Form forms.ModelForm CreateView FormView UpdateView As always, http://ccbv.co.uk is a great resource for deliving into Django forms. django-vanilla-views This should also work … -
Adding Django form instance attributes
Sometimes in the clean(), clean_FOO or save() methods of a Django form, you need to have additional form instance attributes available. A sample case for this is having user_id available. This is a simple example of how to do it in Class-Based Views. Assuming this form: from django import forms from .models import MyModel class MyForm(forms.ModelForm): class Meta: model = MyModel def __init__(self, user_id, *args, **kwargs): super(MyForm, self).__init__(*args, **kwargs) # set the user_id as an attribute of the form self.user_id = user_id Now that the form is defined, the view needs to inject the form with the user id: from django.views.generic import UpdateView # this assumes that django-braces is installed from braces.views import LoginRequiredMixin from .forms import MyForm from .models import MyModel class MyUpdateView(LoginRequiredMixin, UpdateView): model = MyModel form_class = MyForm success_url = "/someplace/" def get_form_kwargs(self): """This method is what injects forms with their keyword arguments.""" # grab the current set of form #kwargs kwargs = super(MyUpdateView, self).get_form_kwargs() # Update the kwargs with the user_id kwargs['user_id'] = self.request.user.pk return kwargs Additional Notes You can use this technique with: forms.Form forms.ModelForm CreateView FormView UpdateView As always, http://ccbv.co.uk is a great resource for deliving into Django forms. While this technique is used … -
virtualenv Lives!
Setting up Python to the point to be able install packages from PyPI can be annoying and time-intensive. Even worse are OS-provided installations that start throwing cryptic error messages. Especially desktops are prone to that but it’s possible to break the whole toolchain of a server by installing some shiny package you heard about on reddit. Your desktop system is unlikely to be a throwaway virtual machine or container. Which makes it a highly mutable system with difficult rollbacks and a lot of pain if stuff breaks1. So until we all run NixOS on our desktops: Don’t install anything into its global site-packages beyond virtualenv. Does that sound extreme to you? Only if you haven’t found the right tools to make it effortless. virtualenv in 2014‽ virtualenv has been around for a while and was a somewhat accepted standard for installing Python software. Sadly, there are many missionaries running around nowadays, boldly proclaiming the end of virtualenv. Mostly because of containers in general and usually because of docker in particular. I find that unfortunate and shortsighted. Frankly, they fail to see the whole picture: virtualenv’s job isn’t just to separate your projects from each other. Its job is also to … -
virtualenv Lives!
Setting up Python to the point to be able install packages from PyPI can be annoying and time-intensive. Even worse are OS-provided installations that start throwing cryptic error messages. Especially desktops are prone to that but it’s possible to break the whole toolchain of a server by installing some shiny package you heard about on reddit. Your desktop system is unlikely to be a throwaway virtual machine or container. Which makes it a highly mutable system with difficult rollbacks and a lot of pain if stuff breaks. So until we all run NixOS on our desktops: Don’t pip-install anything into its global site-packages beyond virtualenv. Does that sound extreme to you1? Only if you haven’t found the right tools to make it effortless. virtualenv in 2014‽ virtualenv has been around for a while and was a somewhat accepted standard for installing Python software. Sadly, there are many missionaries running around nowadays, boldly proclaiming the end of virtualenv. Mostly because of containers in general and usually because of docker in particular. I find that unfortunate and shortsighted. Frankly, they fail to see the whole picture: virtualenv’s job isn’t just to separate your projects from each other. Its job is also to … -
Long Live Adjacency Lists
I recently wrote about the excellent book [SQL Antipatterns](http://pragprog.com/book/bksqla/sql-antipatterns), and in it briefly discussed the tree structures. I've been thinking about trees in [Postgres](http://www.postgresql.org/) a fair bit lately, and a discussion on [#django](https://botbot.me/freenode/django/) gave me further incentive to revisit this topic. The book discusses four methods of storing a tree in a database. *Adjacency Lists*, apart from the inability to grab a full or partial tree easily, are the simplest to understand. The child object stores a reference to it's parent. Because this is a foreign key, then it always maintains referential integrity. Fetching a parent is simple, as is fetching all children, or siblings. It's only when you need to fetch an arbitrary depth that things become problematic, unless you use a recursive query. More on that later. Postgres has an extension called [ltree](http://www.postgresql.org/docs/9.3/static/ltree.html), which provides an implementation of a *Path Enumeration*, but one thing that really bothers me about this type of structure is the lack of referential integrity. In practice, I'm not sure what having this `ltree` structure would give you over simply storing the keys in an `ARRAY` type. Indeed, if Postgres ever gets Foreign Key constraints for ARRAY elements (which there is a patch floating … -
Django-ckeditor-updated and django-ckeditor merge
I've released a new version of django-ckeditor-updated covering all latest changes (full ckeditor 4.4.4 package and some inline editor fixes). The django-ckeditor-updated-4.4.4 can be installed from pypi. Note that there is now a new required configuration variable - CKEDITOR_JQUERY_URL. All outstanding commits have been pushed to django-ckeditor repository (from which I forked) and released as django-ckeditor-4.4.4 (4.4.5 for updated readme). If you are using the "updated" version you can now switch to the django-ckeditor as I plan to make changes there as I now can push pypi releases for it. django-ckeditor-updated is closed. -
Announcing BarCamp Django SF!
BarCamp Django SF! On October 4th and 5th BarCamp Django SF will be taking place in the Eventbrite office in San Francisco. BarCamp Django SF is a low-cost, community-focused event that's different than any previous multi-day Django conference. So how is BarCamp Django SF different than previous Django conferences and events? Speakers are determined at the event I know what you are thinking. It's something on the line of "What the heck?!?" It means that if you want to give a talk, you don't need to be an expert. We don't have an formal, extensive review process. It's a chance to share ideas and learn something new. You can be just a Django hobbyist instead of a professional. All you have to be is passionate. At the event, we'll put up a board with slots for talks. Attendees can put themselves into these slots for talks. This makes for a fun, fluid event where new speakers are as welcome as experienced speakers. While this is meant to be an informal, beginner-friendly event, a professional level of conduct is still required: Speakers, like all attendees must agree to the code of conduct (also listed on the event page). No sales or … -
Announcing BarCamp Django SF!
BarCamp Django SF! On October 4th and 5th BarCamp Django SF will be taking place in the Eventbrite office in San Francisco. BarCamp Django SF is a low-cost, community-focused event that's different than any previous multi-day Django conference. How is BarCamp Django SF different than previous Django conferences and events? Speakers are determined at the event I know what you are thinking. It's something on the line of "What the heck?!?" It means that if you want to give a talk, you don't need to be an expert. We don't have an formal, extensive review process. It's a chance to share ideas and learn something new. You can be just a Django hobbyist instead of a professional. All you have to be is passionate. At the event, we'll put up a board with slots for talks. Attendees can put themselves into these slots for talks. This makes for a fun, fluid event where new speakers are as welcome as experienced speakers. While this is meant to be an informal, beginner-friendly event, a professional level of conduct is still required: Speakers, like all attendees must agree to the code of conduct (also listed on the event page). No sales or recruiting … -
High Performance Django: Shipped
I'm excited to announce that our book, High Performance Django is officially complete. You can buy a copy at highperformancedjango.com now. Thank You Writing the book was hard work and there were definitely times where the challenge felt insurmountable. I couldn't have completed the book without the efforts of a lot of other people: Yann Malet The book's co-author. His real world experience and technical detail were pivotal to the work. Kickstarter Backers Knowing that almost 400 people were counting on having the book was what pushed me through the difficult times. Thank you for putting your faith in the project. Mark Wirblich Mark is behind the design of the book and site. He is new to Lincoln Loop and led the project beautifully. Valerie Coulman Valerie, the book's editor, provided sage advice and the output is far better because of her involvement. Jen Luft Jen managed the delivery of the backer rewards around the world. She is a master of scheduling and coordination. Joni Trythall Joni was in charge of epub and Kindle layouts. She quickly picked up a new set of tools and helped fix some major problems with the small formats. Lincoln Loop Everyone else at Lincoln … -
High Performance Django: Shipped
I'm excited to announce that our book, High Performance Django is officially complete. You can buy a copy at highperformancedjango.com now. Thank You Writing the book was hard work and there were definitely times where the challenge felt insurmountable. I couldn't have completed the book without the efforts of a lot of other people: Yann Malet The book's co-author. His real world experience and technical detail were pivotal to the work. Kickstarter Backers Knowing that almost 400 people were counting on having the book was what pushed me through the difficult times. Thank you for putting your faith in the project. Mark Wirblich Mark is behind the design of the book and site. He is new to Lincoln Loop and led the project beautifully. Valerie Coulman Valerie, the book's editor, provided sage advice and the output is far better because of her involvement. Jen Luft Jen managed the delivery of the backer rewards around the world. She is a master of scheduling and coordination. Joni Trythall Joni was in charge of epub and Kindle layouts. She quickly picked up a new set of tools and helped fix some major problems with the small formats. Lincoln Loop Everyone else at Lincoln … -
My Talk "Factory Boy Fun" at Django London Meetup
On Tuesday I gave another talk at the London Django Meetup Group, titled "Factory Boy Fun", based upon my previous blog post of the same name. The blog post covers pretty much the same stuff, but if you want to flick through the slides quickly for an overview, here they are: -
My Talk "Factory Boy Fun" at Django London Meetup
On Tuesday I gave another talk at the London Django Meetup Group, titled "Factory Boy Fun", based upon my previous blog post of the same name. The blog post covers pretty much the same stuff, but if you want to flick through the slides quickly for an overview, here they are: -
My Talk "Factory Boy Fun" at Django London Meetup
On Tuesday I gave another talk at the London Django Meetup Group, titled “Factory Boy Fun”, based upon my previous blog post of the same name. The blog post covers pretty much the same stuff, but if you want to flick through the slides quickly for an overview, here they are: -
How to add a group choice combo box in a Django user profile form
Assume that you have a Django project where each user belongs to just one group, say Registered or Admin, but not both. You want to show a form in your front-end to let Admin users edit the user profiles, where each user profile is made with First name, Last name, Email and the user group. This task can be accomplished very easily! What you need is a customized ModelForm to add the possibility to edit the user group together with the other fields, and a customized UpdateView to let you set the form initial data for the group field, and to save the changes correctly. Here is the ModelForm: from django import forms from django.contrib.auth.models import User, Group class UserProfileForm(forms.ModelForm): group = forms.ModelChoiceField(queryset=Group.objects.all(), required=True) class Meta: model = User fields = ['first_name', 'last_name', 'email', 'group'] That is a standard ModelForm for the User model, we have just added a group field that is a ModelChoiceField, that is a combo box with all available groups in our project as choices, if you want you can filter the queryset according to your needs. We have also restricted the fields shown in the user profile form to First name, Last name, Email and … -
Understanding get_absolute_url
URL's can be a pain at times, but with get_absolute_url on your model it can make dealing with them on a per-object basis much simpler and cleaner accross your entire site. Not to mention Django itself loves to use get_absolute_url, so it will make other tasks a lot easier.Watch Now... -
DjangoCon 2014: Recap
Caktus had a great time at DjangoCon in Portland this year! We met up with old friends and new. The following staff gave talks (we’ll update this post with videos as soon as they’re available): Mark Lavin, Technical Director, gave two talks: Anatomy of a Django Project and REST: It’s Not Just for Servers. In the photos, you’ll also notice Mark doing some signings of Lightweight Django, his O’Reilly book (already a bestseller on O’Reilly’s list). Karen Tracey, Lead Developer, Technical Manager, Django core committer, and Django Software Foundation member (whew!) answered the question “What is the Django Admin Good For?”. We helped design the website, so it was gratifying seeing the hard work of our design team displayed on the program ad and various points throughout the conference. For fellow attendees, you probably noticed our giant inflatable duck, who came out in support of Duckling, our conference outings app. He told us he had a good time too. Here’s some pictures of our team at DjangoCon: