2009/7/9 Viktor Semykin <thesame...@gmail.com>:
>
> Hi everyone.
>
> I'm trying to generate slugs automatically and disallow user to
> interfere with this. I think way to go is something like:
>
> class Entry(Model):
>     title=CharField(max_length=100)
>     slug=SlugField(default=slugify(...title...))
>
> but I have no idea how to pass title field (or at least model
> instance) to slugify function. Any idea how to solve?

Overriding the save method [1] would be one way to do it:

    def save(self, **kwargs):
        self.slug = slugify(self.title)
        super(Entry, self).save(**kwargs)

Regards,
Jonathan.

[1] 
http://docs.djangoproject.com/en/dev/topics/db/models/#overriding-predefined-model-methods

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to