Changes between Version 2 and Version 3 of SlugifyUniquely


Ignore:
Timestamp:
Mar 23, 2010, 10:18:29 AM (15 years ago)
Author:
semen1
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • SlugifyUniquely

    v2 v3  
    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], 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, [http://bestresearchpapers.net research paper] or [http://www.exclusive-essays.com/exes/Custom-Essays custom essay]. 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, [http://bestresearchpapers.net research paper] or [http://www.exclusive-essays.com/exes/Custom-Essays custom essay]. 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.[http://www.resumesplanet.com resume writers]
     2
     3
    24
    35Feel free to suggest improvements to 'wam-djangowiki spam@wamber.net' (remove the ' spam' from the address there).
Back to Top