Django 1.5 Custom User GeoManager
AttributeError: ‘GeoManager’ object has no attribute ‘get_by_natural_key’
Using geo fields on a Django model requires the use of GeoManager. Custom User models require an object manager that implements BaseUserManager.get_by_natural_key. If you’re trying to add geo fields to your custom User model you’ll need create a custom manager that mixes a user manager and GeoManager. Lucky us, this is a piece of cake!
Create Text & Online Versions of Emails Automatically
For this i’ve created django-firstclass. Firstclass is a proxy email backend for Django that allows for global email transformations such as automatically creating a plain text version of html emails or automatically creating an online version of the email that can be read in browser.
My goal was to have this be a drop in solution requiring no change to a code base. I also wanted this to be flexible enough so that it can work with a wide variety of projects. I accomplished this by adding a middleware pipeline to Django’s email process. I’ve bundled a few useful middleware in and plan to add a few more. Creating your own middleware is simple. Middleware is a single Python class that defines process_message.
For example if you wanted to create a middleware that would add a tracking pixel to all of your emails:
http://gist.github.com/3048960
You would then simply add TrackingPixelMiddleware to FIRSTCLASS_MIDDLEWARE.
Quick Optional Model Fields Trick
This is just something I do now. It’s DRY, saves a few keystrokes, helps stay under pep8’s 79 character limit, and improves readability in my opinion.
My Django 1.4 Project Template
Django supports custom project templates as of 1.4. This is a feature i’ve been dreaming for and since have created what I consider - and hope - is an improved project template for most.
https://github.com/amccloud/django-project-skel/
Changes and additions
- Global templates, static, and fixtures directory.
- Collects static and media into public/{static,media} respectively.
- Django admin activated by default.
- Django timezone setting changed to UTC for sanity.
- HTML 5 base template with simple 404 and 500 error templates.
- Discourages storing credentials and secrets in the repository.
- Encourages the use of local_settings.py and accompanying __local_settings.py template.
- Encourages the use of virtualenv and virtualenvwrapper.
- Encourages the use of pip and requirements.txt.
- Encourages the use of git.
- Includes a .gitignore for the usual junk.
- Automatically builds a README with installation notes.
How to use
django-admin.py startproject --template https://github.com/amccloud/django-project-skel/zipball/master --extension py,md yourprojectname
