Changes between Version 5 and Version 6 of SlugifyUniquely


Ignore:
Timestamp:
Mar 3, 2011, 10:25:44 AM (14 years ago)
Author:
Aymeric Augustin
Comment:

Revert SEO spam

Legend:

Unmodified
Added
Removed
Modified
  • SlugifyUniquely

    v5 v6  
    1 It's common for me to want a unique slug based on a user supplied name of an object. Following the pattern outlined at [http://www.b-list.org/weblog/2006/11/02/django-tips-auto-populated-fields djang-tips-auto-populated-fields] and some useful instructions from [http://www.superiorpapers.com research papers], it's easy to get the field populated without user intervention. However, by setting the slug field in the save() method the field isn't validated and thus unique=True restrictions aren't checked. I wrote the following code to attempt to pick slugs which are unique within a particular model. It's certainly not ideal (it suffers from race condition as well as potential for pounding a database with lots of small queries until it finds a good slug field), but it works for my small/mid-sized apps.
     1It's common for me to want a unique slug based on a user supplied name of an object. Following the pattern outlined at [http://www.b-list.org/weblog/2006/11/02/django-tips-auto-populated-fields djang-tips-auto-populated-fields], it's easy to get the field populated without user intervention. However, by setting the slug field in the save() method the field isn't validated and thus unique=True restrictions aren't checked. I wrote the following code to attempt to pick slugs which are unique within a particular model. It's certainly not ideal (it suffers from race condition as well as potential for pounding a database with lots of small queries until it finds a good slug field), but it works for my small/mid-sized apps.
    22
    33Feel free to suggest improvements to 'wam-djangowiki spam@wamber.net' (remove the ' spam' from the address there).
Back to Top