def get_or_create(self, **kwargs): "Gets or creates a selection. If the selection is created, a slug is given to it." new_slug = None if 'slug' in kwargs: new_slug = slugify(kwargs['slug']) kwargs = self._update_kwargs(kwargs) if new_slug: kwargs['defaults'] = kwargs.get('defaults') or {} kwargs['defaults']['internal_slug'] = new_slug instance, created = super(SelectionManager, self).get_or_create(**kwargs) if created: instance.assign_slug_by_id() instance.save() return instance, created
def create(self, **kwargs): if 'slug' in kwargs: kwargs['internal_slug'] = slugify(kwargs.pop('internal_slug')) kwargs = self._update_kwargs(kwargs) return super(SelectionManager, self).create(**kwargs)
def slug(self, string): self.internal_slug = slugify(string)