SLUG_INDEX_SEPARATOR = '-' # the "-" in "foo-2"
AutoSlugField is an extended SlugField able to automatically resolve name
assert slug, 'value is filled before saving'
- setattr(instance, self.name, slug) # XXX do we need this?
+ # make the updated slug available as instance attribute
+ setattr(instance, self.name, slug)
- #return super(AutoSlugField, self).pre_save(instance, add)
def _get_prepopulated_value(self, instance):
"""Returns preliminary value based on `populate_from`."""
def _generate_unique_slug(self, instance, slug):
Generates unique slug by adding a number to given value until no model
- is found with such slug. If ``unique_with`` (a tuple of field names) was
- specified for the field, all these fields are included together
+ instance can be found with such slug. If ``unique_with`` (a tuple of field
+ names) was specified for the field, all these fields are included together
in the query when looking for a "rival" model instance.
self.name, '", "'.join(self.unique_with)))
if isinstance(field, DateField): # DateTimeField is a DateField subclass
- parts = 'year', 'month', 'day'
+ parts = 'year', 'month', 'day'
granularity = parts.index(inner) + 1