cjahangir
cjahangir

Reputation: 1797

assign list of string to a taggable field

I have a list s where,

s = 'The name of my country is Bangladesh'

I converted the string into list of strings like below:

ss = s.split()

Again, in my database model I have a field keywords

keywords = TaggableManager(_('keywords'), blank=True, help_text=keywords_help_text)

I want to assign the list of string ss to the field keywords. I tried below:

keywords = ss

but I got error. I want to assign the list of string to my taggfield.

Upvotes: 0

Views: 54

Answers (1)

sprksh
sprksh

Reputation: 2384

Seems that you are doing it the wrong way.

You have some class in which you have this keyword field which is efffectively a many to many relationship with another model (something like 'Tags')

How you use it is:

lets say the class is Fruits then you will have to take the instance of that class say Mango(the object you want to create keywords for)

Then you use:

Mango.keywords.add(ss)

or

self.keywords.add(ss)

Upvotes: 1

Related Questions