djangosnippets.org: Latest snippets tagged with 'slug'http://djangosnippets.org/tags/slug/2019-10-17T10:14:57.330299-05:00a better Django Slug Unique Generator
2019-10-17T10:14:57.330299-05:00ParsaFakharhttp://djangosnippets.org/snippets/10680/<p>let say the user chooses the name "Elsa Frozen"
now his slug would be "Elsa-Frozen-5"</p>
<p>it means 4 other people have used the same header
now he can go to url: "your website.com/Elsa-Frozen-4" to see other people's Post</p>
Freely redistributableDjango Generate Unique Slug
2018-02-17T03:36:28.930102-06:00agusmakmunhttp://djangosnippets.org/snippets/10643/<p>Generate unique slug refference by another field.</p>
Freely redistributableGenerate unique slug
2018-01-17T17:45:36.639876-06:00hieunv495http://djangosnippets.org/snippets/10635/<p>generate unique slug</p>
Freely redistributablemadslug
2011-08-24T17:36:23.772439-05:00catellarhttp://djangosnippets.org/snippets/2529/<p>this will turn</p>
<p>ikfjji34 iojwe# eijdf#@$iojdfg 234oijdfg</p>
<p>into</p>
<p>ikfjji_iojwe_eijdfiojdfg_oijdfg</p>
Freely redistributableAutomatic slug generation signal
2011-06-25T05:44:00.826148-05:00danuxhttp://djangosnippets.org/snippets/2471/<p>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.</p>
<p>USAGE:
from django.db.models.signals import pre_save</p>
<p>from YOURPACKAGE import slug_generator</p>
<p>pre_save.connect(slug_generator, sender=YOURMODEL)</p>
Freely redistributableslugify with transliteration
2010-11-26T05:05:13.164923-06:00jezdezhttp://djangosnippets.org/snippets/2274/<p>This slugify correctly transliterates special characters using the translitcodec package from PyPI.
</p>
<p>Make sure you've installed http://pypi.python.org/pypi/translitcodec/ before using this.
</p>
Freely redistributableAutoSlugField and unique_slugify combined
2010-01-20T12:15:13.312148-06:00Ciantichttp://djangosnippets.org/snippets/1877/<p>Extra field for slugs that does the work.
</p>
<p>If the slug value is given, the value is not recreated but correctness is ensured. If value is not given, the field regenerates the slug.
</p>
Freely redistributableEnsure submitted slugs do not conflict with existing resolvable URLs
2009-06-26T18:17:37.885527-05:00ElfSternberghttp://djangosnippets.org/snippets/1598/<p>This code overrides the existing RegistrationForm in django-registration and adds a new validation step. In this step, the username (my example slug) is compared against all the existing URLs that the application currently resolves and, if it <em>does</em> successfully resolve, throws a validation exception. This indicates that the username chosen …</p>
Freely redistributablejQuery slugify plugin
2009-05-05T11:42:25.072907-05:00girasquidhttp://djangosnippets.org/snippets/1488/<p>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:</p>
<p>jQuery('#id_title').slugify('#id_slug');</p>
Freely redistributableunique_slugify
2009-02-12T18:27:57.539584-06:00crucialfelixhttp://djangosnippets.org/snippets/1321/<p>sorry, this is a duplicate post, original is here:</p>
<p>http://www.djangosnippets.org/snippets/690/</p>
<p>no way to delete snippets</p>
Freely redistributableYAAS (Yet Another Auto Slug)
2008-05-22T19:03:20.845796-05:00carljmhttp://djangosnippets.org/snippets/770/<p>This is the self-populating AutoSlugField I use. It's not the <a href="http://www.djangosnippets.org/tags/slug/">first such snippet</a>, but (IMO) it works a bit more cleanly. It numbers duplicate slugs (to avoid IntegrityErrors on a unique slug field) using an "ask-forgiveness-not-permission" model, which avoids extra queries at each save. And it's simply a custom …</p>
Freely redistributableAutomate unique slug (again)
2008-05-17T13:35:58.913433-05:00davidwtbuxtonhttp://djangosnippets.org/snippets/761/<p>This takes the "easier to ask forgiveness than permission" approach to making sure your model's slug is unique.</p>
<p>If the model's slug is empty, make a slug from the model's 'name' field.</p>
<p>We assume that it is a conflicting slug that is throwing the IntegrityError, in which case if the …</p>
Freely redistributableAuto slug field
2008-04-28T05:43:51.128638-05:00GaretJaxhttp://djangosnippets.org/snippets/728/<p>New field type which allows prepopulate_from to work not only from javascript but in python too.
If the slugfield has unique=True creates a unique slug too.
</p>
Freely redistributableUnique Slugify
2008-04-08T20:03:18.595684-05:00SmileyChrishttp://djangosnippets.org/snippets/690/<p>Automatically create a unique slug for a model. </p>
<p>Note that you <em>don't</em> need to do <code>obj.slug = ...</code> since this method updates the instance's slug field directly. All you usually need is: <code>unique_slugify(obj, obj.title)</code></p>
<p>A frequent usage pattern is to override the <code>save</code> method of a model and call <code>unique_slugify …</code></p>
Freely redistributableAutomate unique slugs
2007-12-16T01:43:04.199179-06:00taojianhttp://djangosnippets.org/snippets/512/<p>If you want unique values for a slug field, but don't want to bother the user with error messages, this function can be put into a model's save function to automate unique slugs. It works by appending an integer counter to duplicate slugs.</p>
<p>The item's slug field is first prepopulated …</p>
Freely redistributable