Package: django-friendship
django-friendshipThis application enables you to create and manage follows, blocks and bi-directional friendships between users. It features:Friendship request objects that can be accepted, rejected, canceled, or marked as viewed.Hooks to easily list all friend requests sent or received by a given user, filtered by the status of the request.A blocklist for each user of users they've blocked.Tags to include information about friendships, blocks and follows in your templates.Integration withAUTH_USER_MODEL.Validation to prevent common mistakes.Faster server response time through cachingRequirements** Django 3.2 since v1.9.1 **Previously:Django 1.11+since v1.7.0 (latest release supportingDjango 1.10is v1.6.0)Installationpip install django-friendshipadd"friendship"toINSTALLED_APPSand runpython manage.py migrate.Use the friendship manager in your own views, or wire up the URLconf to include the builtin views:urlpatterns=[...path('friendship/',include('friendship.urls'))...]Note: If you are migrating from django-friendshipv1.6.x, you'll need to rollback your migrations and fake
migration0002$./manage.pymigratefriendship0001$./manage.pymigratefriendship0002--fakeIf you're migrating fromv1.7.x, you'll likely have to fake0003as well:$./manage.pymigratefriendship0003--fakeUsagedjango-friendshipprovides a free API that gives you several ways to create and manage friendship requests or follows in your views. Add the following at the top of yourviews.py:fromdjango.contrib.auth.modelsimportUserfromfriendship.modelsimportFriend,Follow,BlockGetting Data about FriendshipsList all of a user's friends:Friend.objects.friends(request.user)List all unread friendship requests:Friend.objects.unread_requests(user=request.user)List all unrejected friendship requests:Friend.objects.unrejected_requests(user=request.user)Count of all unrejected friendship requests:Friend.objects.unrejected_request_count(user=request.user)List all rejected friendship requests:Friend.objects.rejected_requests(user=request.user)Count of all rejected friendship requests:Friend.objects.rejected_request_count(user=request.user)List of all sent friendship requests:Friend.objects.sent_requests(user=request.user)Test if two users are friends:Friend.objects.are_friends(request.user, other_user) == TrueGetting Data about FollowsList of a user's followers:Follow.objects.followers(request.user)List of who a user is following:Follow.objects.following(request.user)Getting Data about BlocksList of a user's blockers:Block.objects.blocked(request.user)List of who a user is blocking:Block.objects.blocking(request.user)Test if a user is blocked:Block.objects.is_blocked(request.user, other_user) == TrueManaging Friendships and FollowsCreate a friendship request:other_user=User.objects.get(pk=1)Friend.objects.add_friend(request.user,# The senderother_user,# The recipientmessage='Hi! I would like to add you')# This message is optionalLet the user who received the request respond:fromfriendship.modelsimportFriendshipRequestfriend_request=FriendshipRequest.objects.get(from_user=request.user,to_user=other_user)friend_request.accept()# or friend_request.reject()To remove the friendship relationship betweenrequest.userandother_user, do the following:Friend.objects.remove_friend(request.user,other_user)Make request.user a follower of other_user:Follow.objects.add_follower(request.user,other_user)Make request.user block other_user:Block.objects.add_block(request.user,other_user)Make request.user unblock other_user:Block.objects.remove_block(request.user,other_user)TemplatesYou can usedjango-friendshiptags in your templates. First enter:{%loadfriendshiptags%}Then use any of the following:{%friendsrequest.user%}{%followersrequest.user%}{%followingrequest.user%}{%friend_requestsrequest.user%}{%blockersrequest.user%}{%blockingrequest.user%}Signalsdjango-friendshipemits the following signals:friendship_request_createdfriendship_request_rejectedfriendship_request_canceledfriendship_request_acceptedfriendship_removedfollower_createdfollowing_createdfollower_removedfollowing_removedblock_createdblock_removedContributingDevelopmenttakes place on GitHub. Bug reports, patches, and fixes are always welcome!Need help?REVSYScan help with your Python, Django, and infrastructure projects. If you have a question about this project, please open a GitHub issue. If you love us and want to keep track of our goings-on, here's where you can find us online: