Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch: add a TagField object for more natural use of tags. #7

Closed
GoogleCodeExporter opened this issue Mar 26, 2015 · 9 comments
Closed

Comments

@GoogleCodeExporter
Copy link

The attached patch (which is really just an added file) adds a TagField
object (in ``tagging.fields``) that allows more natural access to tags on
tagged items. You define it thusly::

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

    class MyModel(models.Model):
        ...

        tags = TagField()

And then use it pretty naturally::

    >>> from myapp.models import MyModel
    >>> m = MyModel.objects.get(...)

    >>> m.tags = "foo bar"
    >>> m.tags
    "bar foo"

    >>> m.tags = "foo bar baz"
    >>> m.tags
    "bar baz foo"


Original issue reported on code.google.com by jacob.ka...@gmail.com on 11 Mar 2007 at 2:03

Attachments:

@GoogleCodeExporter
Copy link
Author

Fantastic stuff - thanks, Jacob.

Added in revision 28.

Keeping this open until I add the docs for it.

Original comment by jonathan.buchanan on 11 Mar 2007 at 5:52

  • Changed state: Started
  • Added labels: Type-Enhancement
  • Removed labels: Type-Defect

@GoogleCodeExporter
Copy link
Author

Currently, this will blow up when you try to assign tags when initially 
creating an
object, as it hasn't been saved yet when __set__ is called.

Is this something that can be worked around?

Original comment by jonathan.buchanan on 11 Mar 2007 at 11:50

  • Added labels: ****
  • Removed labels: ****

@GoogleCodeExporter
Copy link
Author

Ah, that's because the object doesn't have a primary key yet. Let me explore 
how I
might defer setting tags until later...

Original comment by jacob.ka...@gmail.com on 12 Mar 2007 at 3:29

  • Added labels: ****
  • Removed labels: ****

@GoogleCodeExporter
Copy link
Author

OK, attached is a first stab at making tag assignment to unsaved items work. 
It's a
pretty nasty hack, though, so we should spend a bit of time looking for better 
options.

Original comment by jacob.ka...@gmail.com on 12 Mar 2007 at 4:25

  • Added labels: ****
  • Removed labels: ****

Attachments:

@GoogleCodeExporter
Copy link
Author

That last nasty patch had a bug in it; attached is a fix.

It's still nasty, though.

Original comment by jacob.ka...@gmail.com on 12 Mar 2007 at 2:58

  • Added labels: ****
  • Removed labels: ****

Attachments:

@GoogleCodeExporter
Copy link
Author

Applied the patch in revision 33 - I applied the goggles while checking the 
patch in,
but they did nothing :)

Original comment by jonathan.buchanan on 12 Mar 2007 at 10:57

  • Added labels: ****
  • Removed labels: ****

@GoogleCodeExporter
Copy link
Author

This seems to throw an AttributeError when trying to delete a tagging instance. 
It seems to be calling an 
attribute '__tags_save_defered_tags' which no longer (or never did) exist.

Original comment by jeffwheeler on 16 Mar 2007 at 10:03

  • Added labels: ****
  • Removed labels: ****

@GoogleCodeExporter
Copy link
Author

After looking at `delete_objects` in django.db.models.query, I've modified 
`TagField`
in revision 36 to delete tags when the `pre_delete` signal is dispatched.

The `delete_objects` function sets the primary key attribute to `None` before
dispatching the `post_delete` signal, but we need the primary key to be on the
instance when making the call to `TagManager.update_tags`.

Original comment by jonathan.buchanan on 17 Mar 2007 at 11:13

  • Added labels: ****
  • Removed labels: ****

@GoogleCodeExporter
Copy link
Author

Patched again in issue 13.

Original comment by jonathan.buchanan on 11 May 2007 at 2:15

  • Changed state: Fixed
  • Added labels: ****
  • Removed labels: ****

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant