fabric wsgi deployment strategy
automated deployments using fabric
automated deployments using fabric
For historical reasons, Django commands are hard-coded to use `en-us` regardless of language. This includes the `shell` command and can lead to surprising effects if one assumes the local language to be the one set by `LANGUAGE_CODE`. This snippets can be saved as a management command in any app, for example using the name `lshell` and provides a localized shell controlled by the normal `LANGUAGE_CODE` setting.
If you use django admin interface and have added an admin page for a model, django gives out-of-box search functionality in the model fields or foreignkey fields. One thing it doesn't support is searching in child models. For example you have created an admin page for Student model and there is model for courses which stores one or more courses taken by students and if you want to search by course name on the student page to see which students took a particular course. Django doesn't let you do that. I have written a small utility which will let you do that. Just copy the snippet in a file and then inherit from the ChildSearchAdmin instead of ModelAdmin and then you can specify which model/fields you want it to search on. The syntax is: **child_searches = [(ChildModel, 'field_to_search_on', 'foreign_key_field_in_child_model'),..] Example: class StudentAdmin(ChildSearchAdmin): child_searches = [(StudentCourse, 'course', 'student')]
in template: {% if not list|seeany %} list empty {% else %}
Decorators to attach middleware to class based views w/o arguments.
Automatically load models when their IDs appear in the URL-path. See docstrings for usage and example.
MultiForm and MultiModelForm Based on a PrefixDict class I wrote and thus very lean. Lacks a little documentation, though class MyMultiForm(ModelMultiForm): class Meta: localized_fields = '__all__' form_classes = OrderedDict(( ('form1', Form1), ('form2', Form2), )) Subfields are named `form-name` `prefix_sep` `subfield-name`. `prefix_sep` defaults to `-`. For access in templates, use `form.varfields`, which uses `var_prefix_sep` (default: `_`), instead. multiform.varfields()['form1_field1']
How to use: {% load highlight %} {{ text|highlight:'word' }}
Disable editing adding and deleting inline models in django admin on editing parent model
A very simple way of automatically loading data on model creation. As I am using South I wanted an automatic way of loading initial data only when a new model is create during a migration. Django provides almost everything out of the box by providing the *post_syncdb* signal (triggered also by South migrate command) and the *loaddata* command. The code will simply look for a an existing fixture named `<model>_initial.*` and invoke the *loaddata* command to try to load it Note: beware *post_syncdb* signal is deprecated since version 1.7: it has been replaced by *post_migrate*.
See http://stackoverflow.com/questions/927729/how-to-override-the-verbose-name-of-a-superclass-model-field-in-django/24475838#24475838
**Designed to hold a list of pages and page ranges for a book/magazine index.** A custom model field (and accompanying form field) that saves comma-separated pages and page ranges in human-readable string form. Includes some clean-up code, so that you can add a new page or range at the end of an existing entry, and it will put it in numeric order and combine runs into ranges. So this: 4-33, 43, 45, 60-65, 44, 59 becomes the tidy 4-33, 43-45, 59-65 **NOTE:** If you comment out the raising of the `ValidationError` in the form field's validate() method, it will actually clean up any extraneous characters for you (which could be dangerous, but for me is usually what I want), so even this horrible mess: ;4-33, 46a fads i44 ,p45o gets cleaned to 4-33, 44-46 *This is the first custom field I've ever written for Django, so may be a little rough but seems to work fine.
jQuery code for making custom list on Admin page in DateTime widget. Create new js file in your static folder with this code. To use add custom js to Admin page like this: class NiceAdmin(admin.ModelAdmin): class Media: js = ('js/adminNice.js',) This code will change **all** DateTime widgets on selected page.
A simple way to force SSL on all pages. It's very simple at this point - the only issue I can see right now and I will address this later is if someone sends http:// in another portion of your url.
Your MEDIA_ROOT directories are a mess? FileField save on "upload_to" directories with old/strange/temporary names decided "on the fly" and never fixed down? SmartFolderFileField is the solution! "upload_to" directory depends only on: app, model and field names. No mess, no ambiguities Obviously, in case you need a real callable for a dynamic directory name: please use it! and leave apart FixedFolderFileField Sample: from django.db import models from utilities_app.models import SmartFolderFileField class SampleModel(models.Model): sample_char_field = models.CharField(max_length=50) sample_file_field = SmartFolderFileField()