Last active
August 27, 2020 16:01
-
-
Save mentix02/5306128b90059afa0fe50c36ec26ddd7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_follows = models.ManyToManyField('User', blank=True, related_name='followed_by') | |
objects = UserManager() | |
REQUIRED_FIELDS = ['email', 'password'] | |
def unfollow(self, user: User) -> None: | |
""" Helper function to remove a user from this users following list. """ | |
self._follows.remove(user) | |
def follow(self, user: User, force: bool = False) -> None: | |
""" Helper function to add user to a follower list. """ | |
self._follows.add(user) | |
@property | |
def following(self) -> models.QuerySet: | |
""" Returns a QuerySet of Users that this user follows. """ | |
return self._follows.all() | |
@property | |
def followers(self) -> models.QuerySet: | |
""" Returns a QuerySet of Users following this user. """ | |
return self.followed_by.all() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment