If you try to use multiple inheritance with a modelform (to mix in some fields from an already existing form class for example) you'll get the following rather terrifying error:
> "Error when calling the metaclass bases metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases"
The solution is to first create the ModelForm, then create a NEW class that inherits from both the ModelForm and the form you want to mixin, then finally apply the recipe from here: [http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/204197](http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/204197)
"Sharedance is a high-performance server that centralize ephemeral key/data pairs on remote hosts, without the overhead and the complexity of an SQL database." [Frank DENIS](http://sharedance.pureftpd.org/project/sharedance)
django.contrib.formtools in preview displaying only field.data by default. Its not convenient to see integer value for fields with radio buttons or select choices.
This custom tag trying to show string value from choices if available.
This custom filter is helpful if you want to convert plain text to include html line breaks but you aren't sure if the text is actually plain text or if it already contains html line breaks.
First the filter looks for if the text contains any br, p, or table tags, if it does the text is returned as is. If it doesn't then the same functionality as the [linebreaks](http://www.djangoproject.com/documentation/templates/#linebreaks) filter is applied to the text.
[See blog post](http://paltman.com/2008/04/11/keeping-contenttypes-and-permissions-updated-without-syncdb/)
You can put this script in the root of your project and run after deploying updates in your production environment.
This middleware checks for xhtml mimetypes if the browser supports a "application/xhtml+xml" response. If not, it converts the response headers to "text/html".
To enable this middleware add it the the MIDDLEWARE_CLASSES setting and make sure it appears somewhere after GZipMiddleware, so that it's processed first.
This template tag and suggested template allow greater control over rendering `<label>` tags for your newforms fields than using `field.label_tag`. I save the provided Python code in my app as `templatetags/forms.py` (although this name may conflict in the future).
The simplest usage:
{% label field %}
One use case is adding `class="required"` to the label tag for required fields instead of inserting markup elsewhere--this is done in the given example template.
Alternate label text and tag attributes can be passed to the inclusion tag:
{% label field "Alt. label" 'class=one,id=mylabel' %}
NOTE: this is for **newforms-admin**
I need edit links for items on my site, outside of the django admin -- however, I'm lazy, and don't want to build my own edit forms when there's a perfectly nice admin already there.
Trick is, I need to be able to click a link to the django admin edit page for an item, and have it return to the calling page after saving.
This chunk of code does the trick (the "real" version extra cruft, naturally) -- the links will bring up the django admin editor, then return to the calling page after saving.
Automatically create a unique slug for a model.
Note that you *don't* need to do `obj.slug = ...` since this method updates the instance's slug field directly. All you usually need is: `unique_slugify(obj, obj.title)`
A frequent usage pattern is to override the `save` method of a model and call `unique_slugify` before the `super(...).save()` call.
As a demo, I was asked to write a `render_to_file()` function to load a template and render it to a file. Turns out it's amazingly easy, and I think it's a neat trick to have in your bag of tools.
This snippet is extracted from my Photo model. I use it to ensure that any uploaded image is constrained to a specified size (resized on save).
In my case, I don't need to maintain a "thumbnail" and "fullsize" version, so I just store the resized version to save space.