python - Appending to CommaSeperatedIntegerfield in django -
i created model has commaseparatedintegerfield
models.py
class forumposts(models.model): .... path = models.commaseparatedintegerfield(blank=true,max_length=50) ... i want use model , defined view below views.py
def create_forum_post(request, ..): ... forumpost.path.append(forumpost_id) ... i encountered situation had append forumpost_id integer path defined commaseperatedintegerfield. while debugging got error
'unicode' object has no attribute 'append'.
i think might due lack of comma tried lot of variations of same code unable add forumpost_id path. in advance
commaseparatedintegerfield's value not deserialized automatically, feature of field type validation (it must comma seperated integers).
you need retrieve field value, deserialize it, append new integer, serialize , save back.
edit 1:
example:
class forumposts(models.model): # ... def append_to_path(self, value): path_list = self.path.split(',') path_list.append(value) self.path = ','.join(path_list) usage:
forumpost.append_to_path(forumpost_id) forumpost.save() # save validate if path correct
Comments
Post a Comment