def save(self): if self.instance:#update photo=self.instance old_txt_tags_set=txt2set(photo.get_txt_tags()) to_remove_tags_set=old_txt_tags_set-self.d_txt_tags_set to_add_tags_set=self.d_txt_tags_set-old_txt_tags_set photo.add_txt_tags(to_add_tags_set) photo.remove_txt_tags(to_remove_tags_set) from datetime import datetime photo.modification_date=datetime.now() else: photo = Photo() #上传图片 photo.user=self.user filename=upload_photo(self.cleaned_data['photo'], self.cleaned_data['photo'].name.split('.')[-1]) photo.photo_url=filename photo.title=self.cleaned_data['title'] from oldphoto.utils.textconvert import plaintext2html photo.descn=plaintext2html(self.cleaned_data['descn']) #处理tags,删除删除的tag,添加新增加的tags photo.txt_tags=self.cleaned_data['txt_tags'] photo.save() if not self.instance:#update photo.add_txt_tags(self.d_txt_tags_set) photo.save() return photo
def save(self): from oldphoto.utils.textconvert import plaintext2html comment=plaintext2html(self.cleaned_data['comment']) photo_comment = PhotoComment(author=self.author,\ photo=self.photo,comment=comment) self.photo.rep_count=self.photo.rep_count+1 self.photo.save() photo_comment.save()
def save(self, type): msg=Message(rec_user=self.rec_user_obj,send_user=self.user,type=type,\ title=self.cleaned_data['title'], read='u',\ content=plaintext2html(self.cleaned_data['content'])) msg.save()