sry guys...wrong list please delete this message! On Mar 8, 11:32 am, andreas schmid <[email protected]> wrote: > hi, > > im thinking about how to make my slug generation a bit more functional. > > I dont want my users to think or write their slugs so they have to be > generated by a field in the model. usually this is the title field. > Now the problem is that there is the possibility that a slug could be > the same as one of another object in my app. > Of couse because i dont want the users to edit or write their slugfields > a 'unique=True' doesnt help because it would invalidate the form > and the user wouldnt understand why. > > i was thinking to put a bit of logic in the models save or use the > pre_save signal. > > def save(self): > if not self.slug: > genslug = slugify(self.title) > obj = MyModel.objects.filter(slug=genslug) > if not obj: > self.slug = slug > else: > #do something to generate an unique slug > super(MyModel, self).save() > > would something like this work? > when does the field validation happen?
-- You received this message because you are subscribed to the Google Groups "Google App Engine" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.
