Tag: django

select foo, count(*) from bar group by foo in django

Every once in a while you need some old fashion SQL style queries in django. This is a common one for reporting and aggregation.  Its fairly easy to replicate in a queryset.  Say I wanted to get the authors and the number of articles they have written going back to the beginning of 2009 to the present: The result:

Some reading from django-nyc

Went to the django-nyc meetup last night, it was in Manhattan and much easier to get to then when it's at huge in bk.  Wrote down a few things to read up on: Celery - Celery is an asynchronous task queue/job queue based on distributed message passing. It is focused on real-time operation, but supports scheduling as well. Django ideas - Voting on things with limited numbers of votes to spread around, ala UserVoice Google tech meetup Google prediction api Nyc js Ben Firshman class based views Django con blip…

Developing with multiple versions of Django on windows

At work, we have sites that use various versions of Django, so there is a need to switch packages.  On my mac I use virtualenv to handle this, but I've never quite gotten it to play nice with windows, and just switching Django versions has sufficed so far. If you can set up virtualenv, that's a much better solution Download junction (think symbolic links for windows). Put the executable somewhere in your path. I put it in my Python scripts folder Plan out your directory structure: Make sure you don't have…

Making virtualenv on windows with powershell a little cleaner

While I code on a mac at home, I can't live without my giant dual screens and solid state drive at work so I'm on a windows 7 box.  Most of the time it's fine, does everything I need, and I'm happy.  I became full of rage for the first time last week trying to properly get virtualenv to play nice with powershell.  (If you code on windows and are in the terminal a lot, switch to powershell, its great and comes with windows 7. There is a download for Windows XP) I'm not going to recap how to set up virtualenv…

Getting Started with Solr and Django

Solr is a very powerful search tool and it is pretty easy to get the basics, such as full text search, facets, and related assets up and running pretty quickly. We will be using haystack to do the communication between Django and Solr. All code for this can be viewed on github. Install Assuming you already have Django up and running, the first thing we need to do is install Solr. Next install pysolr and haystack. (At the time of this writing the git checkout of haystack works better with the Solr 4.0 beta…

Generating an InlineModelAdmin Form on the fly in Django

I'm adding drag/drop uploading to the django admin for one of our open source projects called Stager. A blog post about that will follow, it's not screen-shot ready yet.  While doing this I knew we needed a pretty seamless transition after the upload finished, and that we would have to refresh the inline.  I didn't want a full page refresh, so let's ajax it in. For these examples just assume that we have a parent CompAdmin which has an model of Comp and an inline called CompSlideInline.  We store the…