So, I'm trying to extend the Tag-model in tagging.models the following
way:

from django.db import models
from tagging.models import Tag

class TagContext(models.Model):
        context = models.ForeignKey( Tag, unique=True,
related_name='context' )
        parent = models.ForeignKey( Tag, related_name='children_set')

        def __unicode__(self):
                return context.name

If I create two tags:

tag1 = Tag(name='tag1')
tag1.save()
tag2 = Tag(name='tag2')
tag2.save()

followed by a a TagContext:

ctx = TagContext(context=tag2, parent=tag1)
ctx.save()

I can easily reference both 'parent' and 'context':

>>> ctx.context
<Tag: tag1>
>>> ctx.parent
<Tag: tag2>

but I can't go from a tag to context:
>>>ctx1 = tag1.context
>>>ctx
<django.db.models.fields.related.RelatedManager object at 0x1015a5c90>

What am I doing wrong? Shouldn't the 'unique=True' make this sort of
like a onetoone thing (which I was told you should be using instead of
a OneToOne for some reason)? Or is there an other way of doing this.

PS: The tagging.models.Tag has a field called 'parent' that is self-
referential. Is this what I should be using instead? It just doesn't
seem like it's directly accessible..

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.


Reply via email to