コード例 #1
0
ファイル: models.py プロジェクト: danjac/localhub
 def with_has_flagged(self, user, annotated_name="has_flagged"):
     """
     Adds True if the user in question has flagged the object.
     """
     return self.annotate(
         **{
             annotated_name:
             boolean_value(False) if user.
             is_anonymous else get_generic_related_exists(
                 self.model, Flag.objects.filter(user=user))
         })
コード例 #2
0
ファイル: models.py プロジェクト: danjac/localhub
    def with_is_new(self, recipient, annotated_name="is_new"):
        """Annotates "is_new" to queryset if notification(s) unread for
        this object.

        Args:
            recipient (User)
            annotated_name (str, optional): the annotation name (default: "is_new")

        Returns:
            QuerySet
        """
        return self.annotate(
            **{
                annotated_name:
                boolean_value(False) if recipient.
                is_anonymous else get_generic_related_exists(
                    self.model,
                    Notification.objects.
                    filter(is_read=False, recipient=recipient),
                )
            })
コード例 #3
0
ファイル: models.py プロジェクト: danjac/localhub
 def exists_bookmarks(self, user):
     return get_generic_related_exists(self.model,
                                       Bookmark.objects.filter(user=user))
コード例 #4
0
ファイル: models.py プロジェクト: danjac/localhub
 def with_is_flagged(self, annotated_name="is_flagged"):
     """
     Adds True if the object has been flagged by a user.
     """
     return self.annotate(
         **{annotated_name: get_generic_related_exists(self.model, Flag)})
コード例 #5
0
 def exists_likes(self, user):
     return get_generic_related_exists(self.model,
                                       Like.objects.filter(user=user))