Sometimes you have an uncontrolled amount of text in a horizontally constrained space.
The wrappable filter places zero-width breaking spaces into the given text so that it can wrap at any point, as necessary for the containing width. Sometimes better than eliding (chopping long text...) or cropping/scrolling overflow.
It is supposed the aggregation on integer is fast than numeric type in database duo to how they are stored as numeric is represented as string. As money only have 2 decimal place, it can be converted to an Integer despite of its decimal point.
The python class decimal.Decimal also has a shortcoming that it is not json serializable(neither cjson nor simplejson). This money field appears as a float number to the front end, so it does not meet the headache as DecimalField.
The usage is very simple.
In Model:
class SomeModel(models.Model):
...
income = MoneyField('income')
...
Then treat the attribute of the model instance as a normal float type.
**Notes**
If you try to use aggregation on this field, you have to convert it to float by yourself. Currently I could not find any method to fix this.
This Template Tag computes the font-size of two given arguments and returns a CSS-encoded string like "font-size: XXpx;", which can be used to format the font-size of link. (The minium font-size must be set with CSS.)
Requires two arguments:
1. occurrence of the current tag
2. sum of all occurrences
It works great for my tag-cloud.
[Source of the logarithmic formula](http://www.php.de/php-fortgeschrittene/44928-tag-cloud-algorithmus-fuer-schriftgroessye.html)
**Usage**
`<a href="http://www.anything.com" {% cloudify variable.occurrence overall. occurrence_sum %} title="anything">any tag</a>`
Truncates a string after a certain number of chars.
Question:
> *Why don't you use the built-in filter slice?*
I need the "three points" (...) only when it really truncates.
This function lets you save an instance of a model to another database based on a connection argument. Useful when doing data migrations across databases. Connection is anything that would work as a django.db.connection
I'm not sure if this handles proxy models or model inheritance properly, though.
Search engines might conclude there's duplicate content if `/some_view/` and `/some_view/?page=1` returns the same results. This middleware redirects `?page=1` to the URL without the page parameter. You can set the name of the parameter in settings.py as `PAGE_VAR`.
See [here](http://www.muhuk.com/2009/08/a-civilized-way-display-lots-of-data/) for more details.
Template filter to add the given number of tabs to the beginning of each line. Useful for keeping markup pretty, plays well with Markdown.
Usage:
{{ content|indent:"2" }}
{{ content|markdown|indent:"2" }}
This is useful to run before you add a unique key to a character field that has duplicates in it. It just adds numbers to the end of the contents, so they will be unique.
It takes a model class and a field name. The model class can be a South fake orm object, so this can be used inside data migrations.
By default all forms created using inlineformset_factory are displayed as tables (because there is only a .as_table method) and there are no .as_p or .as_ul methods in them, so you need to do that by hand.
Limit ManyToMany fields in forms. Hide the field, if only one item can be selected. e.g. For limit sites choices only to accessible sites.
Also available via django-tools: http://code.google.com/p/django-tools/
A filter that re.matches a regex against a value. Useful for nav bars as follows:
{% if location.path|match:"/$" %} class="current"{% endif %}
For `location.path` see my [location context_processor](/snippets/1685/).
You're looking at the most-bookmarked snippets on the site; if you'd like to help useful snippets show up here, sign up for an account and you'll get your own bookmarks list.