
We continue to share our experience of using useful Django batteries.
First partWe also recommend
“Confused notes about python and django” and
“Django PR Hero project: what's inside and the experience gained .
”For Django written a huge number of packages. Of these,
we chose 10, which we used ourselves in our latest projects and with which we were satisfied. All of them are on PyPI. They are documented and covered with tests, somewhere more, somewhere less. The exception is django-sphinx, about which separately.
')
django-hvad
An interesting implementation of storing multilingual fields in models. For each model being translated, an additional table is created in which only translation attributes are stored.
Model description example:
class DjangoModel(TranslatableModel): name = models.CharField(max_length=255, unique=True) author = models.CharField(max_length=255) translations = TranslatedFields( description = models.TextField(), description_author = models.CharField(max_length=255), ) def __unicode__(self): return self.name
Request example:
DjangoModel.objects.language('en').filter(description_author='Jonas Obrist')
The application is one of the best in its category, albeit alpha. In some places it is damp, as the author himself admits. It tries to minimize the number of queries to the database, friendly to south-migrations.
In addition, django-hvad can draw a nice admin panel for field translations:
GithubDocumentationdjango-whatever (django-any)
The module eliminates the creation of bulky fixtures for tests, replacing them with simple creation of model objects on the fly, filling the fields with random data. Thanks to this, tests become more readable and supported.
Here is an example in which we create two instances of models, but specify when creating only those field values that are important for the test (the rest will be done by django-any):
from django_any import any_model class TestMyShop(TestCase): def test_order_updates_user_account(self): account = any_model(Account, amount=25, user__is_active=True) order = any_model(Order, user=account.user, amount=10) order.proceed() account = Account.objects.get(pk=account.pk) self.assertEquals(15, account.amount)
django-any wrote kmmbvnr
habrauser , and django-whatever is a friendly fork of our authorship, in which we
added a few features and fixed a few bugs .
GithubDocksdjango-jenkins
Convenient integration of Django and Jenkins to simplify the solution of continious integration from kmmbvnr. Everything is very simple: you configure and use, there are no complaints.
Good articles about testing in Django and directly about integration with django-jenkins:
GithubVideo tutorial from the author: “How to start testing and get pleasure from it”django-guardian
The application implements the missing out of the box feature of the rights to the object, and not to the entire model (object-level permissions). Starting with Django 1.2, the authentication backend
supports object permissions checking, but this is not implemented in Django itself. django-guardian successfully fills this space.
The only flaw found is, perhaps, the fact that the existence of global rights to the model does not give rights to a specific object and
requires separate verification .
GithubDocksdjango-email-confirmation
Among the many other similar batteries, django-email-confirmation does not take on everything at once, but what it takes does it well. Allows the user to register several email addresses for himself, select the main one from them, confirm addresses by mail and manage the whole simple process. You can define your own templates for letters, you can make friends a method of sending letters with Celery, all as expected. It is part of the Pinax project.
Githubdjango-compressor / webassets
Two of the most interesting, in our opinion, applications for gluing and minifying CSS / JS. Unlike the django-compress mentioned in the previous post, they do not require a config and can work using template tags, which is quite convenient for layout designers. webassets, which is notable, works not only with Django (
flask-assets ). Both modules support
Jinja through their extensions. Fans of SAS, LESS, CoffeeScript will not leave offended, preprocessors are also supported.
We use django-compressor and warn you against hasty updates on the latest versions of the application on the combat servers: the module is being actively developed and unexpected regressions periodically emerge (despite the tests). The rest is a very good package from one of the django core devs.
django-compressor githabdjango-compressor docksgithab webassetswebassets docksdjango-taggit
Simple battery, both in structure and in capabilities. As the name implies, django-taggit implements tag support. He does this at the model level with the help of a special manager. It is not bad customized and expands through the through-model, he himself is able to create a tag cloud that has already filled everyone, and does some other standard things (like adding / removing a tag). Documentation is quite small, but comprehensive, so familiarity will not take much time.
GithubDocksdjango-sphinx
Sphinx, a popular search engine, is our all, thanks to its speed, flexibility and ability to take into account the peculiarities of Russian morphology, which cannot be said about its closest competitors. Despite its popularity, there is one single integrator solution for Django - django-sphinx.
What gives?
- full support for the Sphinx API <= 0.9.9
- Search queries through the model manager, you can specify parameters such as field weights or index names directly in the model class description
- based on the specified parameters, can automatically generate sphinx-config
- pseudo`queryset (SphinxQueryset) on the output, which is also convenient for working with sampling
And at the same time:
- there are problems with additional processing of the sample object
- some annoying open bugs in the original django-sphinx package (for example, exception when using the exclude method), although they are fixed in our fork
- no tests at all, poor documentation
- the package is not supported and no longer developed by its author
In the coming days, we will share with you our experience with this module and will try to describe in detail the detected pitfalls. A lot of nuances pulls into a separate article.
Github (our fork)Useful articles (in some places not quite relevant):
django-celery
A truly indispensable battery on more or less large projects, where asynchronous tasks are indispensable. In fact, Celery is the de facto standard for queuing in python, it has a wide range of features, supports a variety of backends and has a nice API.
Habré had a couple of good articles on how to work with celery, including tuning and pitfalls when integrating with Django:
GithubDocumentationdjango-hosts
The module for managing the routing of URLs depending on the subdomain, each of which can have its own URLConf. If your site has many subdomains, this battery will be useful to you.
GithubDocumentationPS Our modest contribution to the open source
github.com/futurecolors and
github.com/coagulant