[ckan-dev] Create free-form tag programmatically?

Vitor Baptista vitor at vitorbaptista.com
Wed Mar 27 00:56:13 UTC 2013


Hi Ryan,

AFAIK, there're two ways to do what you want. You could create a new Tag by
using the model directly and adding it to the package you want, as in:

    my_tag = model.Tag('my-tag')
    package.add_tag(my_tag)
    package.save()

Or you could simply do:

    package.add_tag_by_name('my-new-tag')

This will create a free tag with that name, if one doesn't exist yet.

Does this solve your problem?

Cheers,
Vítor Baptista.

2013/3/26 Ryan Clark <ryan.clark at azgs.az.gov>

> I'm trying to figure out how to add free-form (vocabulary-free) tags to a
> package programmatically, and I'm finding the documentation a little
> confusing.
>
>
> http://docs.ckan.org/en/latest/ckan.logic.action.create.html#ckan.logic.action.create.package_createsays I can add tags and "see tag_create() for the format of tag
> dictionaries"
>
> http://docs.ckan.org/en/latest/ckan.logic.action.create.html#ckan.logic.action.create.tag_createsays "To create a new free tag simply add the tag to a package, e.g. using
> the package_update function"
>
> http://docs.ckan.org/en/latest/ckan.logic.action.update.html#ckan.logic.action.update.package_updatedoesn't really specify how to use it, so I tried:
>
> package_update({"id": "my-package-id", "tags": [ "some", "free", "tags"]})
>
> However that complains that it wants tags in dictionary format, as I would
> use for specifying tags that are part of a vocabulary. How do I specify a
> free tag?
>
> Also, what is the best way to access the tags once I have them entered? I
> ran into a situation where my_package.package_tags contained a tag, but
> my_package.get_tags() returned an empty list?
>
> Thanks so much!!
>
>   ____________________
>
> Ryan Clark
> Arizona Geological Survey
> ryan.clark at azgs.az.gov
> (520) 302-4871
>
>
>
>
>
>
>
>
> _______________________________________________
> ckan-dev mailing list
> ckan-dev at lists.okfn.org
> http://lists.okfn.org/mailman/listinfo/ckan-dev
> Unsubscribe: http://lists.okfn.org/mailman/options/ckan-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.okfn.org/pipermail/ckan-dev/attachments/20130326/82a50bef/attachment-0001.html>


More information about the ckan-dev mailing list