I have Django model that looks like this:
class Categories(models.Model):
"""
Model for storing the categories
"""
name = models.CharField(max_length=8)
keywords = models.TextField()
spamwords = models.TextField()
translations = models.TextField()
def __unicode__(self):
return self.name
class Meta:
verbose_name = _('Category')
verbose_name_plural = _('Categories')
The fields keywords
, spamwords
and translations
contain huge chunks of comma-separated text. Could someone tell how I could write a function inside the model which for a particular fieldname, returns the value a list so that I could access it something like this:
cat = Categories.objects.get(id=1)
print cat.keywords.to_array()
...it returns the field data, split into an array. (The splitting bit is very simple and i know how to do that - string.split(',')
Thanks