[ckan-dev] Create free-form tag programmatically?
Adrià Mercader
adria.mercader at okfn.org
Wed Mar 27 10:46:48 UTC 2013
Hi Vitor and Ryan,
On 27 March 2013 00:56, Vitor Baptista <vitor at vitorbaptista.com> wrote:
> 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')
Domain model objects should never be called from extensions as this is
bound to create compatibility problems. All interactions with the
database should be done via logic layer functions ('package_create' or
'tag_create')
>
> 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.
You need something like this:
package_update({"id": "my-package-id", "tags": [ {"name": "some"},
{"name": "free"}, {"name": "tags"}]})
Sorry about the confusion, package_create apidoc should define the tag format.
Do you want to do quick pull request to add it to the docs?
>> 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?
Again, I would recommend not accessing the package object directly,
but using the "package_show" logic function.
You will get a dict similar to this one, with a tags property:
http://demo.ckan.org/api/action/package_show?id=adur_district_spending
Adrià
>>
>> 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
>>
>
>
> _______________________________________________
> 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
>
More information about the ckan-dev
mailing list