On 5/6/2009 9:57 PM, Lee Hinde wrote:
> I have this as part of the model for a class called "Class"
> 
> 
>     def save(self, force_insert=False, force_update=False):
>         start = defaultfilters.slugify(self.Name)
>         count = Class.objects.filter(Slug__equal=start).count()
>         if count != 0:
>             filterme = "%s_%d" % (self.Name, count)
>             self.Slug = defaultfilters.slugify(filterme)
>         else:
>             self.Slug = start
> 
> 
> The reason is, it's ok to have duplicate Names,  and I want to use a
> Slug as the canonical url.
> 
> I have a bunch of data to import and so , in shell I run
> 
>  c = Class.objects.all()
> for o in c:
>     o.save()
> 
> 
> My goal would be to see something like:
> 
> yoga-for-kids
> yoga-for-kids_1
> yoga-for-kids_2
> 
> What's weird is I'm getting:
> 
> yoga-for-kids
> yoga-for-kids
> yoga-for-kids_2
> 
> i.e., I get dupes and then not.
> 
> I've played with it most of the evening and now I'm hoping someone
> with a fresh pair of eyes might have a suggestion.
> 
> Thanks in advance.

I'm not sure why you're getting yoga-for-kids_2, what I expect is 
yoga-for-kids, yoga-for-kids_1, then more yoga-for-kids_1 if your slug 
field is not unique=True.

In any case, your logic will keep generating yoga-for-kids_1 because 
there will only ever be one count for yoga-for-kids in your DB.

-- 
George

--~--~---------~--~----~------------~-------~--~----~
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