Django community: Community blog posts RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Generating aggregate data across generic relations
Edit: I've created a github repo for performing generic aggregation and annotation based on the code from this entry Aggregation support was added to django's ORM in version 1.1, allowing you to generate Sums, Counts, and more without having to write any SQL. According to the docs aggregation is not supported for generic relations. This entry describes how to work around this using the .extra() method. The state of the art To take an example from the docs, it is possible to span relationships when performing aggregations: >>> Store.objects.annotate(min_price=Min('books__price'), max_price=Max('books__price')) Here we are querying the Store object and annotating the result set with two extra attributes, 'min_price' and 'max_price', which contain the minimum and maximum price of books that are sold at that store. Conversely, if we want to find the minimum and maximum book price over the entire queryset, you would write: >>> Store.objects.aggregate(min_price=Min('books__price'), max_price=Max('books__price')) The aggregate() method returns a dictionary as opposed to a queryset. This is an incredibly clean API! Suppose you want to aggregate across a GFK This is tricky. A generic foreign key is comprised of two attributes, a ContentType and a foreign key. The models that are GFKed to do not contain a reverse … -
Generating aggregate data across generic relations
Edit: I've created a github repo for performing generic aggregation and annotation based on the code from this entry Aggregation support was added to django's ORM in version 1.1, allowing you to generate Sums, Counts, and more without having to write any SQL. According to the docs aggregation is not supported for generic relations. This entry describes how to work around this using the .extra() method. The state of the art To take an example from the docs, it is possible to span relationships when performing aggregations: >>> Store.objects.annotate(min_price=Min('books__price'), max_price=Max('books__price')) Here we are querying the Store object and annotating the result set with two extra attributes, 'min_price' and 'max_price', which contain the minimum and maximum price of books that are sold at that store. Conversely, if we want to find the minimum and maximum book price over the entire queryset, you would write: >>> Store.objects.aggregate(min_price=Min('books__price'), max_price=Max('books__price')) The aggregate() method returns a dictionary as opposed to a queryset. This is an incredibly clean API! Suppose you want to aggregate across a GFK This is tricky. A generic foreign key is comprised of two attributes, a ContentType and a foreign key. The models that are GFKed to do not contain a reverse … -
Changed project structure
We really wanted to avoid this, but with the soon-to-be-announced MongoDB backend we realized that our current project structure for djangoappengine-based projects makes portability between different nonrel backends and installation on MongoDB-based projects unnecessarily difficult. Please adapt your project to the new recommended structure. We've published detailed installation instructions in the djangoappengine documentation which also describes how to create symbolic links on Windows 7, Vista, and XP and Linux and MacOS X. What changed The "common-apps" folder is deprecated. From now on, you'll get a warning if that folder exists in your project. The "django", "djangoappengine", and "djangotoolbox" links should now be placed right into your main project folder. We've also moved "djangotoolbox" into a subfolder of the djangotoolbox repository, so please change the link accordingly. That was necessary because we had to add a setup.py installation file for MongoDB users. Also, the app.yaml file has to reflect those changes. Please remove the "common-apps/" prefix from all paths in your app.yaml. See the django-testapp/app.yaml for an example. Finally, replace your manage.py file with the one in django-testapp. Just download the django-testapp/manage.py from the repository and copy it into your projects. Now you can delete the "common-apps" folder. Again, please look … -
Learned Something New Today
I learned something very interesting today regarding JavaScript. Back in the day, I used to put something like this in my HTML when I wanted to include some JS: <script language="javascript"> ... </script> Then I learned that I should be using something like this instead: <script type="text/javascript"> ... </script> I've been doing that for years and years now. Turns out I've been wrong all this time. Well, at least for 4 years of that time. I stumbled upon RFC4329 today for whatever reason and noticed that it said the text/javascript mimetype is obsolete. I dug into the RFC a bit and found this: Various unregistered media types have been used in an ad-hoc fashion to label and exchange programs written in ECMAScript and JavaScript. These include: +-----------------------------------------------------+ | text/javascript | text/ecmascript | | text/javascript1.0 | text/javascript1.1 | | text/javascript1.2 | text/javascript1.3 | | text/javascript1.4 | text/javascript1.5 | | text/jscript | text/livescript | | text/x-javascript | text/x-ecmascript | | application/x-javascript | application/x-ecmascript | | application/javascript | application/ecmascript | +-----------------------------------------------------+ Use of the "text" top-level type for this kind of content is known to be problematic. This document thus defines text/javascript and text/ ecmascript but marks them as "obsolete". Use of experimental … -
Learned Something New Today
I learned something very interesting today regarding JavaScript. Back in the day, I used to put something like this in my HTML when I wanted to include some JS: <script language="javascript"> ... </script> Then I learned that I should be using something like this instead: <script type="text/javascript"> ... </script> I've been doing that for years and years now. Turns out I've been wrong all this time. Well, at least for 4 years of that time. I stumbled upon RFC4329 today for whatever reason and noticed that it said the text/javascript mimetype is obsolete. I dug into the RFC a bit and found this: Various unregistered media types have been used in an ad-hoc fashion to label and exchange programs written in ECMAScript and JavaScript. These include: +-----------------------------------------------------+ | text/javascript | text/ecmascript | | text/javascript1.0 | text/javascript1.1 | | text/javascript1.2 | text/javascript1.3 | | text/javascript1.4 | text/javascript1.5 | | text/jscript | text/livescript | | text/x-javascript | text/x-ecmascript | | application/x-javascript | application/x-ecmascript | | application/javascript | application/ecmascript | +-----------------------------------------------------+ Use of the "text" top-level type for this kind of content is known to be problematic. This document thus defines text/javascript and text/ ecmascript but marks them as "obsolete". Use of experimental … -
South 0.7.1
The first bugfix release of South is now out, and there's plenty of fixes.It's been perhaps a little too long since the 0.7 release, so I'm pleased to announce that 0.7.1 has now arrived. It's really all small changes, as befits a point release - the release notes highlight the few slightly more major changes. In other news, I'll be at djangocon.eu next week, talking about both South up to now, as well as what I think the future holds. The jury's still out on what exactly will happen, but I have a few interesting proposals I'll be talking about, some of which are a bit more grand than others. If you're not going to be able to make it, don't worry, I'm sure you can all be subjected to me in two-dimensional video form later on. It's a once in a lifetime experience, mostly because few people are awake enough to try listening to it a second time. I'll also obviously be posting my proposals here and in other appropriate places, to gauge feedback. -
South 0.7.1
The first bugfix release of South is now out, and there's plenty of fixes. It's been perhaps a little too long since the 0.7 release, so I'm pleased to announce that 0.7.1 has now arrived. It's really all small changes, as befits a point release - the release notes highlight the few slightly more major changes. In other news, I'll be at djangocon.eu next week, talking about both South up to now, as well as what I think the future holds. The jury's still out on what exactly will happen, but I have a few interesting proposals I'll be talking about, some of which are a bit more grand than others. If you're not going to be able to make it, don't worry, I'm sure you can all be subjected to me in two-dimensional video form later on. It's a once in a lifetime experience, mostly because few people are awake enough to try listening to it a second time. I'll also obviously be posting my proposals here and in other appropriate places, to gauge feedback. -
Exciting Python Developer Job
Meebo, the instant messenger in your browser company, are seriously looking for Python developers right now to work in Mountain View, California. From what I can gather they are expanding, and are building a number of sites in the Django framework. -
Exciting Python Developer Job
Meebo, the instant messenger in your browser company, are seriously looking for Python developers right now to work in Mountain View, California. From what I can gather they are expanding, and are building a number of sites in the Django framework. Meebo are hiring! If you have experience with Django, or some other web framework, and you live in California (or can relocate) this may be an excellent opportunity for you to work for a cool technology company. Contact Kiko Griffin if you're interested — and please mention where you read this! See Meebo's job page for more information… -
Exciting Python Developer Job
Meebo, the instant messenger in your browser company, are seriously looking for Python developers right now to work in Mountain View, California. From what I can gather they are expanding, and are building a number of sites in the Django framework. Meebo are hiring! If you have experience with Django, or some other web framework, and you live in California (or can relocate) this may be an excellent opportunity for you to work for a cool technology company. Contact Kiko Griffin if you're interested — and please mention where you read this! See Meebo's job page for more information… -
Another book to review! (Django E-Commerce)
The nice folks at Packt has sent me another book to review. This time the book is Django 1.2 E-Commerce. The sample title looks great which includes setting up an e-commerce site in 30 mins using the usual suspects from the Django framework: Admin, generic views and using Checkout from google. The example looks practical and easy to follow ... makes me like this book already. For those of you who want to get a whiff of what this book is like ... here is a link to the sample chapter.https://www.packtpub.com/sites/default/files/7009-chapter-2-setting-up-shop-in-30-minutes_0.pdf -
Review: Django 1.1 Testing and Debugging
The lovely people of Packt Publishing asked me to review Karen Tracey's latest book Django 1.1 Testing and Debugging. I didn't actually read the book but rather skimmed it, apart from some selected parts and from what I read it's obvious that Karen has an ability to write to people who are not experts on the subject. Years of being a top contributor on the Django users mailing list must have something to do with it. But here's the cracker. I didn't learn anything from this book (actually, I wasn't aware of the pp command in the pdb debugger). Is that a complaint about the book? No! It just means that the book was aimed at beginners and apparently I'm not a beginner any more. Great! One thing I would have liked to see is more about testing strategy since this is something beginners often have problems with. I don't know if there even is such a word as "testing strategy" but I'm referring to the thinking behind what to test and more importantly sometimes what not to test. Beginners have a tendency to write tests for the most specific things and thus spending all their time assuring the most … -
Facebook wall like application in Django - part 1
Creating Facebook Wall-like or Twitter-like Django application for small social, intranet or collaboration sites. Part 1 - playing with models and queries. -
GitHub and django-articles
Some of you who prefer to use git for your version control needs and were following the django-articles mirror on GitHub may have noticed some strange activity recently. I noticed today that the GitHub mirror was out of sync with the other mirrors, and I took a bit of time to investigate the problem. I thought, for some reason, that I might be able to quickly and easily bring it back into sync if I just deleted the repo, recreated it, and pushed my changes to it. That didn't work. This means that all of you who were once following the project there are no longer following it, and I only realized that side effect after I had clicked the delete button. I apologize for this inconvenience. In the end, it turned out that I had some things misconfigured with git on my box. I have resolved the problems and have brought the mirror back into sync. Please let me know if you run into any problems with it! -
New Feature in django-articles: Articles From Email
One of the features that I really like about sites like posterous and tumblr is that they allow you to send email to a special email address and have it be posted as a blog article. This is a feature I've been planning to implement in django-articles pretty much since its inception way back when. I finally got around to working on it. The latest release of django-articles allows you to configure a mailbox, either IMAP4 or POP3, to periodically check for new emails. A new management command check_for_articles_from_email can be used to process the messages found in the special mailbox. If any emails are found, they will be fetched, parsed, and posted based on your configuration values. Only articles whose sender matches an active user in your Django site will be turned into articles. You can configure the command to mark such articles from email as "inactive" so they don't appear on the site without moderation. The default behavior, actually, is to mark the articles inactive--you must explicitly configure django-articles to automatically mark the articles as active if you want this behavior. One of the biggest things that you should keep in mind with this new feature, though, is … -
GitHub and django-articles
Some of you who prefer to use git for your version control needs and were following the django-articles mirror on GitHub may have noticed some strange activity recently. I noticed today that the GitHub mirror was out of sync with the other mirrors, and I took a bit of time to investigate the problem. I thought, for some reason, that I might be able to quickly and easily bring it back into sync if I just deleted the repo, recreated it, and pushed my changes to it. That didn't work. This means that all of you who were once following the project there are no longer following it, and I only realized that side effect after I had clicked the delete button. I apologize for this inconvenience. In the end, it turned out that I had some things misconfigured with git on my box. I have resolved the problems and have brought the mirror back into sync. Please let me know if you run into any problems with it! -
New Feature in django-articles: Articles From Email
One of the features that I really like about sites like posterous and tumblr is that they allow you to send email to a special email address and have it be posted as a blog article. This is a feature I've been planning to implement in django-articles pretty much since its inception way back when. I finally got around to working on it. The latest release of django-articles allows you to configure a mailbox, either IMAP4 or POP3, to periodically check for new emails. A new management command check_for_articles_from_email can be used to process the messages found in the special mailbox. If any emails are found, they will be fetched, parsed, and posted based on your configuration values. Only articles whose sender matches an active user in your Django site will be turned into articles. You can configure the command to mark such articles from email as "inactive" so they don't appear on the site without moderation. The default behavior, actually, is to mark the articles inactive--you must explicitly configure django-articles to automatically mark the articles as active if you want this behavior. One of the biggest things that you should keep in mind with this new feature, though, is … -
djangoappengine updates: IN and != queries and DecimalField
Django-nonrel's App Engine backend (djangoappengine) now finally supports all query features available on App Engine. Additionally, we now support DecimalField, thanks to Mariusz Kryński! Let's start with "!=" query support. You can now create queries like this: Post.objects.exclude(category='sql') This has the same behavior as the App Engine code Post.all().filter('category !=', 'sql'). Internally, this actually gets converted into two queries (even with App Engine's native API): "category > 'sql'" and "category < 'sql'". We also now support IN queries like this one: Post.objects.filter(category__in=['django', 'NoSQL']) This has the same behavior as the App Engine code Post.all().filter('category IN', ['django', 'fun']). Again, internally this gets converted into two queries: "category = 'django'" and "category = 'NoSQL'". Note that you can't create queries which would need more than 30 sub-queries. Finally, you can now use DecimalField: from decimal import Decimal from django.db import models class DecimalModel(models.Model): decimal = models.DecimalField(max_digits=9, decimal_places=2) result = DecimalModel.objects.get(decimal=Decimal('45.60')) The difference between decimals and floats is that decimals are exact whereas a floats have rounding errors. For example, if you enter "2.3" this into a Python console you get: >>> 2.3 2.2999999999999998 In contrast, a decimal would stay exactly "2.3". So, what's next? During this Google I/O we might get to … -
django-moderation new release 0.2 - status update
Today i have released new version of django-moderation - 0.2. It has been uploaded in to pypi, so now it can be installed with easy_install. Many bugs were fixed and many new features were added since initial release. List of changes Added GenericModerator class that encapsulates moderation options for a given model.Changed register method, it will get only two parameters: model class and settings class. Added option to register models with multiple managers. Added options to GenericModerator class: auto_approve_for_superusers, auto_approve_for_staff, auto_approve_for_groups, auto_reject_for_anonymous, auto_reject_for_groups. Added methods for checking auto moderation. Added automoderate helper function. Changed moderated_object property in ModerationManager class, moderated object is get only once from database, next is cached in moderatedobject, fixed issue with not setting user object on changed_by attribute of ModeratedObject model. Fixed issue when loading object from fixture for model class that is registered with moderation. Now moderated objects will not be created when objects are loaded from fixture. Fixed issue with TypeError when generating differences of changes between model instances that have field with non unicode value ex. DateField. Fixed issue with accessing objects that existed before installation of django-moderation on model class. Fixed issue when more then one model is registered with moderation and … -
New Django Site – Blog Twin
I created Blog Twin after reading a blog post by Viper Chill entitled The Secret to growing your blog twice as fast with half the effort, I decided to create a site that would help people find a blogging partner. Blog Twin is written in Django (naturally!). You register, add details of your blog, and [...] -
Backend supported Backup/Restore
The current application data is now ready to be backed-up, and restored as and when required.Present application data can now be exported as JSON fixtures, to get a snapshot of the current application datastore state. At present it'll export the following objects:BlogsUsersAuthorsPostsCommentsThe backup scripts uses Django Serialization to store the objects into files, and are deserialized into native python objects when restoring.Thus, now backup and restore of the online project contents is possible. Currently, this can only be done from the backend, but later a more restricted version of it will be available from the front-end too. -
Backend supported Backup/Restore
The current application data is now ready to be backed-up, and restored as and when required.Present application data can now be exported as JSON fixtures, to get a snapshot of the current application datastore state. At present it'll export the following objects:BlogsUsersAuthorsPostsCommentsThe backup scripts uses Django Serialization to store the objects into files, and are deserialized into native python objects when restoring.Thus, now backup and restore of the online project contents is possible. Currently, this can only be done from the backend, but later a more restricted version of it will be available from the front-end too. -
Free to comment
The commenting system is now available.Although it is going to be still under development, and more features might be added to it. It's now totally usable by others, none the less.The current development version of Django does provide a comments framework to work with comments on other existing data models. I still decided not to use it at this point of time. There are two main reasons for that:The comments framework is used as just another Django application (which I don't want to happen in this case), and it's development is not yet stabilized, going through modular and implemention changes.I'm not sure whether I would like to stick to the current system either, and may switch to something like DISQUS. In such a case the porting might be a little less complex.Although I have certain advanced plans for the commenting system, I don't except them to get implemented until a more matured version of ScratchBlog comes through. -
Free to comment
The commenting system is now available.Although it is going to be still under development, and more features might be added to it. It's now totally usable by others, none the less.The current development version of Django does provide a comments framework to work with comments on other existing data models. I still decided not to use it at this point of time. There are two main reasons for that:The comments framework is used as just another Django application (which I don't want to happen in this case), and it's development is not yet stabilized, going through modular and implemention changes.I'm not sure whether I would like to stick to the current system either, and may switch to something like DISQUS. In such a case the porting might be a little less complex.Although I have certain advanced plans for the commenting system, I don't except them to get implemented until a more matured version of ScratchBlog comes through. -
Django 1.2 release notes
Django 1.2 release notes (via). Released today, this is a terrific upgrade. Multiple database connections, model validation, improved CSRF protection, a messages framework, the new smart if template tag and lots, lots more. I’ve been using the 1.2 betas for a major new project over the past few months and it’s been smooth sailing all the way.