Custom Tag for multiple models

205 views
Skip to first unread message

madlit...@gmail.com

unread,
Oct 15, 2013, 2:57:02 PM10/15/13
to django...@googlegroups.com
I want to create a custom tag that includes a description field that will be applied to multiple models such as articles, projects, etc

I have read and understood this page (documentation) but it seems to document a custom tag setup for one model.

I get a error message when trying to add an eTag in the admin panel
FieldDoesNotExist at /admin/ecore/etag/add/
eTag has no field named u'content_type'

What I currently have is this:
from django.db import models
from taggit.models import TaggedItemBase
from django.contrib.contenttypes.generic import GenericForeignKey

# Create your models here.
class eTag(TaggedItemBase):
    content_object = GenericForeignKey()

    description_markdown = models.TextField(
        verbose_name = 'Description (Markdown)',
    )

And use it like so on an "article" model:
tags = TaggableManager(through=eTag) 

My problem may just be that I am using "GenericForeignKey()" but that is what the GenericTaggedItemBase() uses so I assume it is fine. 

How do I set up a custom tag model that allows a description that can be used for tagging multiple models?

Thanks, Eric

madlit...@gmail.com

unread,
Oct 15, 2013, 3:50:51 PM10/15/13
to django...@googlegroups.com, madlit...@gmail.com
Also when I visit a view that has the model I get this error:
FieldError at /blog/2/markdown-test
Cannot resolve keyword u'content_object' into field. Choices are: description_markdown, id, tag

madlit...@gmail.com

unread,
Oct 15, 2013, 4:12:52 PM10/15/13
to django...@googlegroups.com, madlit...@gmail.com
I just ended up just changing the model for TagBase as so:
class TagBase(models.Model):
    name = models.CharField(verbose_name=_('Name'), unique=True, max_length=100)
    slug = models.SlugField(verbose_name=_('Slug'), unique=True, max_length=100)

    description_markdown = models.TextField(
        verbose_name = 'Description (Markdown)',
        blank = True,
    )

Please post a better more elegant solution if you have any ideas. 
Reply all
Reply to author
Forward
0 new messages