Browse Source

Recursively delete HasTag instances and clean tags afterwards

Getty Ritter 11 months ago
parent
commit
9a7d8281c4
3 changed files with 6 additions and 2 deletions
  1. 1 1
      lc/app.py
  2. 4 0
      lc/model.py
  3. 1 1
      stubs/peewee.py

+ 1 - 1
lc/app.py

@@ -198,7 +198,7 @@ class GetLink(Endpoint):
 
     def api_delete(self, user: str, link_id: str):
         u = self.require_authentication(user)
-        u.get_link(int(link_id)).delete_instance()
+        u.get_link(int(link_id)).full_delete()
         return self.api_ok(u.base_url())
 
     def html(self, user: str, link_id: str):

+ 4 - 0
lc/model.py

@@ -313,6 +313,10 @@ class Link(Model):
             for ht in HasTag().select(Tag.name).join(Tag).where(HasTag.link == self)
         ]
 
+    def full_delete(self):
+        self.delete_instance(recursive=True)
+        Tag.clean()
+
 
 class Tag(Model):
     """

+ 1 - 1
stubs/peewee.py

@@ -33,7 +33,7 @@ class Model:
     def save(self):
         pass
 
-    def delete_instance(self) -> Any:
+    def delete_instance(self, recursive: bool = False) -> Any:
         pass
 
     @classmethod