Django Generate Unique Slug
Generate unique slug refference by another field.
- django
- slug
- slugify
- django-slug
Generate unique slug refference by another field.
Better slugify function for national characters. Source of original script: http://trac.django-fr.org/browser/site/trunk/project/links/slughifi.py?rev=47
A pre_save signal that will automatically generate a slug for your model based on the "title" attribute, and will store the new slug in the "slug" attribute. USAGE: from django.db.models.signals import pre_save from YOURPACKAGE import slug_generator pre_save.connect(slug_generator, sender=YOURMODEL)
This slugify correctly transliterates special characters using the translitcodec package from PyPI. Make sure you've installed http://pypi.python.org/pypi/translitcodec/ before using this.
This filter converts slashes to spaces in a a sting and then slugify's the result. However, it ignores leading and trailing slashes. For example, it can take something like this: /some/url/with-an-existing-slug/ And turn it into this: some-url-with-an-existing-slug The filter was originally written to use the *curent* url as the `disqus_identifier` for Disqus comments. For example: {{ request.META.PATH_INFO|slug_and_slash_to_dash }}
This plugin lets you make a field(ideally for a slug) populate itself based on the value of another field. You use it like this: jQuery('#id_title').slugify('#id_slug');
This is based on snippets 29 and 43, both of which had good ideas, and I thought, "why not combine them?" Given the new_topic string above, the resulting slug will be: "test-long-string-which-has-many-words-here" John Crawford Note - requires python 2.5, for list comprehensions. Otherwise you could just use a for loop to build the clean_list.
sorry, this is a duplicate post, original is here: http://www.djangosnippets.org/snippets/690/ no way to delete snippets
Changes **all slugify calls** to support translat automatically, behind the scenes. Using this one doesn't have to change any models or code to make it work everywhere. Create new project, I call it myself *autoslugifytranslat*, and add the following to project's `__init__.py` file. It will automatically add translat slugify support for all default slugify calls. This script is depending on the fact that slugify function in Django is always in *django.template.defaultfilters.slugify*. **Note:** The snippet is supposed to have "ä","Ä" and "ö","Ö" in the `char_translat` list, but djangosnippets does not let me put ä's and ö's to the code part!
I prefer to use this slugification function rather than the one included with Django. It uses underscores instead of dashes for spaces, and allows dashes and periods to occur normally in the string. I decided on this when considering reasonable slugified titles such as... object-relational_mapper_2.5 ten_reasons_web-2.0_rocks django-trunk_0.99_updated
10 snippets posted so far.