Skip to content

Commit

Permalink
updated query
Browse files Browse the repository at this point in the history
  • Loading branch information
pyprism committed Aug 17, 2024
1 parent 5813400 commit 7748ef9
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion diary/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ def create_tag(self, user, tag):
def get_tag(self, user, tag):
return self.filter(user=user, name=tag).first()

def is_tag_exists_for_user(self, user, tag):
return self.filter(user=user, name=tag).exists()

def get_all_tags(self, user=None):
if user:
return self.filter(user=user).order_by('name')
Expand All @@ -19,6 +22,11 @@ def create_diary(self, user, diary, post_type, tag):
return self.create(user=user, diary=diary, post_type=post_type, tags=tag)

def get_diary_by_tag(self, user, tag):
return self.filter(user=user, name=tag).all()
return self.filter(user=user, name=tag).prefetch_related('tags').all()

def get_all_diaries(self, user=None):
if user:
return self.filter(user=user).order_by('created_at').prefetch_related('tags')
return self.order_by('created_at').prefetch_related('tags')


0 comments on commit 7748ef9

Please sign in to comment.