Advertisement
horozov86

Document_Management_Class_Document

Jul 10th, 2023
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.97 KB | None | 0 0
  1. class Document:
  2.     def __init__(self, id, category_id, topic_id, file_name):
  3.         self.id = id
  4.         self.category_id = category_id
  5.         self.topic_id = topic_id
  6.         self.file_name = file_name
  7.         self.tags = []
  8.        
  9.     @classmethod
  10.     def from_instances(cls, id, category: Category, topic: Topic, file_name):
  11.         return cls(id, category.id, topic.id, file_name)
  12.    
  13.    
  14.     def add_tag(self, tag_content):
  15.         if tag_content in self.tags:
  16.             return
  17.         self.tags.append(tag_content)
  18.        
  19.    
  20.     def remove_tag(self, tag_content):
  21.         if tag_content not in self.tags:
  22.             return
  23.         self.tags.remove(tag_content)
  24.    
  25.     def edit(self, file_name):
  26.         self.file_name = file_name
  27.        
  28.    
  29.     def __repr__(self):
  30.         tags_joined = ', '.join(self.tags)
  31.         return f"Document {self.id}: {self.file_name}; category {self.category_id}, topic {self.topic_id}, tags: {tags_joined}"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement