Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
I Hate Generic Foreign Keys, but this works anyway
I'm really not a fan of the concept of Generic Foreign Keys. They do have their place, and the app I've just started is a reasonable example. It's django-activity-streams, and I'm using it essentially as an audit stream. It stores the user who performed the change, the object that was changed, when it was changed, and a serialised version of the fields that have changed, in the format of: {% highlight js %} [ { "field": "date_of_birth", "old": "1955-01-10", "new": "1955-10-01" } ] {% endhighlight %} Now, the complication comes when trying to generate reports based on this stuff, and that is all down to the use of GFKs. Essentially, what I want to be able to do is: {% highlight python %} Action.objects.between(start, finish).verb('updated').filter( target__in=queryset ) {% endhighlight %} But this will not work, as there is no real `target` field: it's a GFK field. But we can query on the two fields that make it up: `target_content_type` and `target_object_id`. So, you might think we can do something like: {% highlight python %} ctype = ContentType.objects.get_for_model(queryset.model) Action.objects.filter( target_content_type=ctype, target_object_id__in=queryset ) {% endhighlight %} Alas, this will not work either, as `target_object_id` is a "character varying", and a queryset kind-of … -
Django Dash - Registration Soon! (And Sponsors Needed)
Django Dash - Registration Soon! (And Sponsors Needed) -
Django Round-Up #8
Lynn Root joins us to discuss the latest Django and Python links, running your own young coders class, and PRISMs effect on us and the technology we use. -
Caktus Participates in DjangoCon 2013
Caktus is happy to be involved in this year’s DjangoCon hosted in Chicago. We are pumped about the great lineup of speakers and can’t wait to see some of our old friends as well as meet some new folks. Beyond going to see the wonderful talks, Caktus is participating as a sponsor and Tobias McNulty will be speaking on scaling Django web apps. Come stop by our booth or see Tobias’ talk to connect with us. Tobias’ talk "Scaling Your Write-Heavy Django App: A Case Study" will delve into some Django related scaling challenges we encountered while developing a write-heavy web app that would be deployed to millions of students and parents in the Chicago public school system. Through the lens of these specific problems he will show widely applicable solutions to forecasting web app loads, scaling, and automating the configuration so that it is completely repeatable. We are proud to support the Django community through our sponsorship and involvement in DjangoCon. We’re all looking forward to the event and hope to see some of you there! -
Caktus Participates in DjangoCon 2013
Caktus is happy to be involved in this year’s DjangoCon hosted in Chicago. We are pumped about the great lineup of speakers and can’t wait to see some of our old friends as well as meet some new folks. Beyond going to see the wonderful talks, Caktus is participating as a sponsor and Tobias McNulty will be speaking on scaling Django web apps. Come stop by our booth or see Tobias’ talk to connect with us. -
Django redirects with regular expressions
Django redirects with regular expressions -
Django Round-Up: DjangoCon Edition
In this special episode, we interview Steve Holden and discuss the history of DjangoCon, what goes into producing a conference, and Steve's personal history with Django. -
Configuring various browsers for Selenium web applications tests
Selenium can test your web applications quite easily (at least the frontend). To perform the tests it launches a webdriver which in most cases will be Firefox. But what about other browsers that may interpret CSS/JS differently, or what about mobile browsers on mobile devices? Selenium does support them, but to get them working some extra configuration is required. In this article I'll show how to make other browsers work with Python Selenium client (on Linux). -
Activity Feed with Event Log
Adding an activity feed is simple with the eventlog application. I show you how to get started with it by easily adding it to your project, and how use and administer it.Watch Now... -
Join me in supporting the Ada Initiative
I believe deeply in the importance of gender equality, yet I work in open source, a community with shockingly few women. The Ada Initiative is working together with people like me to bring more women into open source - and we’re succeeding. That’s why I’m challenging the Python community to help me raise $10,000: I’ll match any donations from the Python community to the Ada Initiative up to a maximum of $5,000. -
Django Round-Up #7
This week Kenneth and Brandon are joined by Julia Elman! -
Catching up
For a while now I’ve been pretty embarrassed by this site. Not by the visual design, or the functionality (though some bits have been lost along the way, for reasons that will become obvious in a moment), but by the fact that it was old. As in, over five years old. It was running on a bunch of ancient code that I’d written a long, long time ago, on an ancient Subversion checkout ... Read full entry -
Catching up
For a while now I’ve been pretty embarrassed by this site. Not by the visual design, or the functionality (though some bits have been lost along the way, for reasons that will become obvious in a moment), but by the fact that it was old. As in, over five years old. It was running on a bunch of ancient code that I’d written a long, long time ago, on an ancient Subversion checkout of Django ... Read full entry -
Django and pip wheel
Just a quick heads-up: older Django versions don't work properly if installed via wheel. It's fixed in 1.6 but it's not final yet (right now it's in beta). Edit: Django 1.5.2 has the fix backported from 1.6. Apparently the older versions of Django list the package data files under the data_files setup.py option and wheel follows the spec to the letter (installs data_files in sys.prefix) while setuptools does not (it treats relative data_files just like package_data entries). If you switched to wheels already you can fix the template loading with something like this: import sys import os from django.template.base import TemplateDoesNotExist from django.template.loader import BaseLoader from django.conf import settings class SysPrefixLoader(BaseLoader): is_usable = True def load_template_source(self, template_name, template_dirs=None): pkg_name = 'templates/' + template_name for app in settings.INSTALLED_APPS: try: return open( os.path.join( sys.prefix, os.path.join(*app.split('.')), pkg_name ), 'rb' ).read().decode(settings.FILE_CHARSET), 'sysprefix:%s:%s' % (app, pkg_name) except Exception: pass raise TemplateDoesNotExist(template_name) And just add module.SysPrefixLoader to TEMPLATE_LOADERS in the settings. For the staticfiles, use this finder: import sys import os from django.contrib.staticfiles.finders import AppDirectoriesFinder, FileSystemStorage class SysPrefixAppStaticStorage(FileSystemStorage): def __init__(self, app, *args, **kwargs): location = os.path.join( sys.prefix, os.path.join(*app.split('.')), 'static' ) super(SysPrefixAppStaticStorage, self).__init__(location, *args, **kwargs) class SysPrefixAppDirectoriesFinder(AppDirectoriesFinder): storage_class = SysPrefixAppStaticStorage And add module.SysPrefixAppDirectoriesFinder to STATICFILES_FINDERS in the … -
Django and pip wheel
Just a quick heads-up: older Django versions don't work properly if installed via wheel. It's fixed in 1.6 but it's not final yet (right now it's in beta). Edit: Django 1.5.2 has the fix backported from 1.6. Apparently the older versions of Django list the package data files under the data_files setup.py option and wheel follows the spec to the letter (installs data_files in sys.prefix) while setuptools does not (it treats relative data_files just like package_data entries). If you switched to wheels already you can fix the template loading with something like this: import sys import os from django.template.base import TemplateDoesNotExist from django.template.loader import BaseLoader from django.conf import settings class SysPrefixLoader(BaseLoader): is_usable = True def load_template_source(self, template_name, template_dirs=None): pkg_name = 'templates/' + template_name for app in settings.INSTALLED_APPS: try: return open( os.path.join( sys.prefix, os.path.join(*app.split('.')), pkg_name ), 'rb' ).read().decode(settings.FILE_CHARSET), 'sysprefix:%s:%s' % (app, pkg_name) except Exception: pass raise TemplateDoesNotExist(template_name) And just add module.SysPrefixLoader to TEMPLATE_LOADERS in the settings. For the staticfiles, use this finder: import sys import os from django import VERSION from django.contrib.staticfiles.finders import AppDirectoriesFinder, AppStaticStorage class SysPrefixStorage(AppStaticStorage): def __init__(self, app, *args, **kwargs): self.app_module = app if self.app_module == 'django.contrib.admin' and VERSION < (1, 4): self.prefix = 'admin' self.source_dir = 'media' location … -
Django Extensions 1.2.0
Django-Extensions version 1.2.0 is out now ! :) ChangeLog: More Python 3 support BACKWARDS COMPATIBILITY: Fixes to the UUID field might break backwards compatibility FEATURE: hook in dumpscript to control execution during run_import FEATURE: add --prof-file option to runprofileserver FEATURE: provide configurable way to obtain Keyczar class FEATURE: IPv6 and FQDN address support in runserver_plus FEATURE: runserver_plus setting for default address/port in settings.py FEATURE: added trvis status image FIX: JSONField did not allow empty list as default value FIX: support Django 1.5 swappable User model FIX: runserver_plus to serve static files correctly FIX: make spatialite work with reset_db FIX: sqldiff missing varchar size under PostGreSQL FIX: removed fallback uuid module FIX: sqlcreate use client hostname not database server hostname for grant FIX: graphmodels version comparison for 0.36 work around -
A Plan Comes Together
Long, hard days of coding, shuffling and teasing Oracle finally come to a close - or do they? I'm very pleased to report that, just before this blog post was published, we merged my schema-alteration branch into Django. It's been a long road, and I'd like to thank everyone who's helped me, especially those who backed my Kickstarter and my fellow core developers, all of whom have been invaluable. This isn't the end of my work, though; it's just the end of the first phase. Migrations are functional but not complete, and the schema backends are passing all of their tests but will still have a few bugs. What next? The next step is twofold; working on improving the documentation (there's still large gaps in the reference documentation), while also adding some missing features, including: Migration squashing. The underlying framework for this in place but the user-facing commands aren't written yet. More Operations, including ones for custom raw SQL and custom Python code (for more complex manipulations) Better merge detection: Currently it just errors, while instead it should be able to resolve some merges automatically. Support for out-of-transaction operations, like CREATE INDEX CONCURRENTLY on PostgreSQL. This will require a little … -
Keep that module out!
Keep that module out! We usually include a local_settings.py file in our Django projects. We use the file whenever some Django settings need to be tweaked according to the environment or specific requirements of individual developers. It was a challenge to find a good way to exclude that file from being installed in production. Read more... -
Writing thread-safe django - get_or_create
In this blog post, we'll discuss thread-safety, why it's important and how to write thread-safe django code, especially for bulk operations like management commands. We'll take a simple example - get or create. Thread-safety: Thread-safety means that our code can be run in multiple threads and behave as expected. The reason that code can be unsafe with regard to threads is because we'll be manipulating shared memory (e.g. database) from the threads and there's a chance of a race-condition which will produce unexpected results. To avoid this, we have the option of using read-write locks, transactions etc. We'll look at some simple examples and try to understand these options. The usual way: Let's consider a management command that syncs data from another source (e.g. API, remote database etc.. The correct way to do this would be to use the built-in django utility - get_or_create: Update: Updated the command to run each arg in a thread class MyThread(Thread): def __init__(self, my_id): super(MyThread, self).__init__(name=my_id) self.my_id = my_id def run(self): instance, created = MyModel.objects.get_or_create(my_id=my_id) print '%s %s' % (instance.id, created) instance.delete() return class Command(BaseCommand): args = '<my_id my_id ...>' help = 'Get or create instace of mymodel with my_id' def handle(self, *args, **options): … -
Django Round-Up #6
This week Kenneth and Brandon are joined by Russell Keith-Magee! -
Django i18n
What does i18n mean? i18n = i followed by 18 letters followed by n = internationalization That is it, just a short hand. It isn't the name of standard governmental or otherwise. When I watched the first videos about Django many years ago, they declared that Django had great internationalization support including a Welsh translation. It sounded great and I wanted to try to use it, but I was never involved in a project that really needed it, until now! At Thalmic Labs we were able to translate the company website into German and Korean in a matter of weeks, the most time was devoted to getting the translations done, very little was figuring out i18n in Django. It was only a few hours of hitting my head against the wall. Here is a bit of what I learned along the way. Hopefully it helps you. Resources First watch this excellent talk by Jacob Burch. He helps to fill in some of the gaps from the i18n documentation which you should also have a look at. Definitely grab Jacob's version of poxx, you won't need it in production or on staging so you can just install it locally: pip install … -
cookiecutter: Project Templates Made Easy
Yesterday, Jeff Knupp wrote an amazing how-to article called "Open Sourcing a Python Project the Right Way". While I was reading it, I was rather pleased by just how close it is to my own practices. Considering Jeff's amazing Writing Idiomatic Python, it meant I was on the right track. The downside, of course, is implementation. Creating reusable Python packages has always been annoying. There are no defined/maintained best practices (especially for setup.py), so you end up cutting and pasting hacky, poorly understood, often legacy code from one project to the other. Some of it does nothing and some of it fails catastrophically on Python 3. There's a term for this sort of behavior, and it's called Cargo Cult programming. Fortunately, while I was ranting and Jeff (and Hynek Schlawack) was writing, someone was making cookiecutter. cookiecutter does one thing and it does it well What cookiecutter does is make creating and maintaining project templates easy and intuitive. This allow developers of all languages (not just Python) the ability to break free from cargo-cult configuration and follow patterns dictated by the experts who present their own cookiecutter templates. So if you don't like how the author of cookiecutter's creates her … -
Cookiecutter: Project Templates Made Easy
Yesterday, Jeff Knupp wrote an amazing how-to article called "Open Sourcing a Python Project the Right Way". While I was reading it, I was rather pleased by just how close it is to my own practices. Considering Jeff's amazing Writing Idiomatic Python, it meant I was on the right track. The downside, of course, is implementation. Creating reusable Python packages has always been annoying. There are no defined/maintained best practices (especially for setup.py), so you end up cutting and pasting hacky, poorly understood, often legacy code from one project to the other. Some of it does nothing and some of it fails catastrophically on Python 3. There's a term for this sort of behavior, and it's called Cargo Cult programming. Fortunately, while I was ranting and Jeff (and Hynek Schlawack) was writing, someone was making cookiecutter. cookiecutter does one thing and it does it well What cookiecutter does is make creating and maintaining project templates easy and intuitive. This allow developers of all languages (not just Python) the ability to break free from cargo-cult configuration and follow patterns dictated by the experts who present their own cookiecutter templates. So if you don't like how the author of cookiecutter's creates her … -
Raspberry IO open sourced
Back in March, at PyCon 2013, the PSF provided each attendee with a Raspberry Pi, a tiny credit-card sized computer meant to be paired with the Python programming language. The power and portability of the Raspberry Pi has stimulated an explosion of interest among hobbyists and educators. Their uses seem to be limited only by our collective imagination. Along with that generous gift, the PSF contracted with Caktus to help tap into this collective imagination. Raspberry IO is a site dedicated to Python and Raspberry Pi enthusiasts. The goal of the site is to serve as a friendly place where anyone can learn and teach about using Python with a Raspberry Pi. We are proud to announce that Raspberry IO is now an open source project. We've written tests and documentation to help you get started and contribute your ideas to the site. Please create an issue at the github repository. We're excited about the possibilities for a site like this in the hands of the Raspberry Pi and Python communities. If you have an interesting Raspberry Pi project, then we'd love for you to tell us about it! Razzy welcomes you! -
Raspberry IO Open Sourced
Back in March, at PyCon 2013, the PSF provided each attendee with a Raspberry Pi, a tiny credit-card sized computer meant to be paired with the Python programming language. The power and portability of the Raspberry Pi has stimulated an explosion of interest among hobbyists and educators. Their uses seem to be limited only by our collective imagination.