Celery ghetto queue
django django · PythonCurrently wondering how the ghetto queue might work for smaller installations. I have done larger installations using RabbitMQ, celery’s preferred message mechanism, but for smaller loads and services running straight from django and postgres might be a good idea. I guess it maintains the flexibility of having an upgrade path but is less to install and maintain, thus being kinder to sysadmins and support staff. Going to try it I think.
Django localization and internationalization
django django · internationalization · localizationWe have been using the localization and internationalization ( l10n& i18n ) from Django quite a bit for our translations, and although we haven’t had to tackle anything difficult like Arabic or Persian yet there are still some shortcomings in the system. The standard Django module for input of dates and datetime stamps is quite restrictive. It depends on a module, I think written by Simon Willson which uses the PHP notation rather than the Python/C strftime / strptime notation.
Django on RedHat or CentOS
Computing · django · Linux centos · django · nginx · redhatI am normally using Debian, Ubuntu or even Suse for deploying Django, but a recent customer needed to deploy on Red Hat Enterprise Server 5. We decided beforehand to test deployment on RHEL5 and also on CentOS 5.4 and so these instructions should work for both environments. NginX will be used as the webserver. The first thing I like to do is to upgrade the repository and add EPEL. This wasn’t needed I found on the RedHat box I was using, but was needed on CentOS but your mileage might vary.
Django staff member required
Computing · django djangoHere is a simple decorator that isn’t mentioned properly in the Django documentation. [cc lang=“python”]@staff_member_required[/cc] It basically checks to see if the user is logged in and has is_staff before allowing a user access to the view. Use like you would the normal @login_required decorator. [cc lang=“python”] from django.shortcuts import render_to_response from django.template.context import RequestContext from django.contrib.admin.views.decorators import staff_member_required @staff_member_required def my_view(request): return render_to_response(‘page.html’, context_instance=RequestContext(request)) [/cc]
Extending Django’s user admin
Computing · django djangoThe built in admin pages that you get in Django can be useful, but they particularly become useful once you start to add a lot more functionality to them. For instance the Django’s User authentication system (which lives in django.contrib.auth ) is widely used, and quite often you need to extend the user’s profile by using AUTH_PROFILE_MODULE and a separate model. But having a separate Admin screen for this is kind of pointless.
Leading zeros in django
Computing · django djangoI am always forgetting about the stringformatting tag in Django’s templating language. For instance for leading zeros: <br /> {{ variable|stringformat:“02d” }}<br /> This will always put a leading zero.
Django test fixtures and contenttypes
Computing · django djangoJust came across an interesting problem with the contenttypes contributed application and the test framework. If you are using fixtures in the test frame work you might find that the database gets out of date as you are working on it, particularly if you are creating new models all the time. To get around this you need to regenerate the contenttypes database. If you depend on this, the following steps could give you problems so make sure that you back up your data (dumpdata) beforehand.
django one form, two models
django · Software · Websites djangoThis post is a work in progress is now working I am glad to say. I have been working on a django site which needs two models updated for one post. It is actually using models very close to that on django-forums and I have created a forms.py file: <br /> class ThreadForm(forms.ModelForm):<br /> class Meta:<br /> model = Thread<br /> exclude = (‘forum’, ‘sticky’, ‘closed’, ‘posts’, ‘views’, ‘latest_post_time’)</p> <p> def clean_title(self):<br /> title = self.
Looks like Django is really taking off
Computing · django · Software · Websites djangoSince the introduction of Google’s appengine which includes support for some of Django’s code, and the template system there has been an incredible amount of press for Django. At the moment there is no backend support for AppEngine in Django (and DB2 support is still lacking – there was a blog post about a year ago but nothing seems to have happened since, and I would love to be proved wrong on that one) but it must only be a matter of time before this happens so for the moment you have to disable the ORM support.
Django and URLS naming
Computing · django · Websites djangoDjango URLs naming can be a pain sometimes, unless it is just me but an easy way to debug is to use Django’s shell and import urlresolvers: </p> <p>python manage.py shell</p> <p>>> from django.core.urlresolvers import reverse<br /> >> reverse(‘nameofurl’)<br /> If there are arguments in the URLS field (for instance passing in the slug): <br /> >> reverse(‘nameofurl’, ‘slug’) [/sourcecode]<br /> Then it should resolve the name to the URL path needed.
Older »