jinjie2088 / django-tagging

Automatically exported from code.google.com/p/django-tagging
Other
0 stars 0 forks source link

Proposed change: add slug to the tags #83

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago

 For using django-tagging with not-ascii tags and accessing them by the
ascii uls, i've used such path:

class Tag(models.Model):
    """
    A basic tag.
    """
....
    slug = models.SlugField(max_length=100,unique=True)
....
    def save(self):
        import pytils
        if not self.slug:
            self.slug=pytils.translit.slugify(self.name)
        super(type(self),self).save()    

So I access tags from templates:
{% tags_for_object entry as entry_tags %}                   
    {% if entry_tags %}
        {% for tag in entry_tags %}
        <a href="/tags/{{tag.slug}}/">{{tag.name}}</a>
        {% endfor %}
    {% endif %}

Original issue reported on code.google.com by got...@gmail.com on 24 Dec 2007 at 1:48

GoogleCodeExporter commented 9 years ago

Original comment by jonathan.buchanan on 29 Dec 2007 at 3:13

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I have done similar to yourself, however am running into some preliminary 
problems..
As you can see our code to add slugs is much the same:

    slug = models.SlugField(max_length=50, unique=True, db_index=True,
prepopulate_from=('name',), validator_list=[isTag], null=True)
    def get_slug(self):
        return self.slug
    def save(self):
        if not self.id:
            if not self.slug:
                from django.template.defaultfilters import slugify
                self.slug = slugify(self.name)
            base = self.slug
            i = 2
            while Tag.objects.filter(slug=self.slug).count():
                self.slug = base+'_'+str(i)
                i += 1
            super(Tag, self).save()

However when I try to use the code:

{% tag_cloud_for_model blog.Post as taglist %}
{% for tag in taglist %}
<a href="/blog/tag/{{ tag.slug }}/"><span style="font-size: {{ tag.font_size 
}}">{{
tag.name }}</span></a>
{% endfor %}

tag.slug is always None - I am guessing this is because the query in 
Tag._get_usage
does not specify a slug, but I've not had time to investigate properly and I am 
tired
- anyone else come across this? I definitely think this project needs the 
addition of
slugs.

Original comment by wrboyce on 29 May 2008 at 10:49

GoogleCodeExporter commented 9 years ago
Here's my patch which adds slug support to django-tagging r154. I'm using it 
right
now with django-trunk and all is well. The slug is regenerated from the name on 
every
save as I figured having a slug that's different from the name didn't make much
sense. I also added a 'created' field to be able to list most recently added 
tags. If
this isn't desirable, I'll remove this feature and re-upload the patch. 

Original comment by ziggur...@gmail.com on 23 Jan 2009 at 2:12

Attachments:

GoogleCodeExporter commented 9 years ago
Any chance of this getting accepted? I really need this functionality, and I'd 
rather not 
like to maintain my own fork :)

Original comment by mik...@hoegh.org on 21 Oct 2009 at 7:33

GoogleCodeExporter commented 9 years ago
I'd love to see this too, especially since there are already proposed patches.

Original comment by ringe...@gmail.com on 18 Nov 2009 at 1:19

GoogleCodeExporter commented 9 years ago
Patch in #4 works for me. If a +1 counts as the patch being well-tested enough, 
can
this be committed please?

Original comment by jazepst...@gmail.com on 4 Jan 2010 at 11:56

GoogleCodeExporter commented 9 years ago
Whoops... just tried deploying django-tagging with this patch to a site running
Postgres (dev is on sqlite), and got a nasty error. "slug" needs to be added to 
2
GROUP BY statements.

Updated patch attached.

Original comment by jazepst...@gmail.com on 5 Jan 2010 at 12:19

Attachments: