Fix pagevote and bookmark bug for new objects

This commit is contained in:
cuom1999 2023-08-03 23:19:45 +07:00
parent 36e27321f7
commit 4ceae6d066
7 changed files with 32 additions and 44 deletions

View file

@ -53,3 +53,13 @@ class MakeBookMark(models.Model):
unique_together = ["user", "bookmark"]
verbose_name = _("make bookmark")
verbose_name_plural = _("make bookmarks")
class Bookmarkable:
def get_or_create_bookmark(self):
if self.bookmark.count():
return self.bookmark.first()
new_bookmark = BookMark()
new_bookmark.linked_object = self
new_bookmark.save()
return new_bookmark