jinjie2088 / django-tagging

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

model.save() fails to retain tags #232

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I am using svn version of django-tagging, but have also tried the version
in the ubuntu repositories (ver .2, I think).  Anyways, I have a simple
model with tagging:

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

class Note(models.Model):
    text = models.TextField()
    tags = TagField()

    def set_tags(self, tags):
        Tag.objects.update_tags(self, tags)

    def get_tags(self):
        return Tag.objects.get_for_object(self)

I open the django shell and create a note:

>>>from myapp.models import Note
>>>note = Note.objects.create()
>>>note.id
4
>>> note.get_tags()
[]
>>> note.set_tags("Hello, World")
>>> note.get_tags()
[<Tag: Hello>, <Tag: World>]
>>> note.save()
>>> note.get_tags()
[]

So, something about saving the object clears the tags.  Now, when I look at
the admin panel for tagging, the tags are created.  But under the tagged
items admin panel, they do not appear.  

Interestingly, if I add a note and add tags to it through the automatically
created admin panel for the Note model, it everything appears to work.

I've looked at the patches in Issue 166, but these don't seem to fix the
problem.  

Any ideas?  

Original issue reported on code.google.com by disneyfr...@gmail.com on 13 Dec 2009 at 9:59

GoogleCodeExporter commented 9 years ago
Uggg. I'm such an idiot.  Apparently calling save() clears the tags by calling
update_tags(), but without sending any tags.  This acts as if you've deleted 
all the
tags.

The solution is to simply not save the note after its initial creation.  (The 
first
save is needed to give the note an id).

Original comment by disneyfr...@gmail.com on 15 Dec 2009 at 2:29

GoogleCodeExporter commented 9 years ago
Seems like you're on the right track already! For some more information, you 
might want to look at #229 and 
read the comments in one of the patches.

Original comment by jonasnoc...@gmail.com on 15 Dec 2009 at 10:21