django-simple-friends adds friendship management to your project.
- Manages relationships between registered users only.
- Two phase friending.
- Blocking.
- Add
"django-simple-friends"
directory to your Python path. - Add
"friends"
to yourINSTALLED_APPS
tuple found in your settings file. - Run
syncdb
to create tables and seed friendship data for existing users. - Include
"friends.urls"
to your URLconf. (optional)
You can use the project in the example
directory in repository to run tests:
python example/manage.py test friends
Note that if you have installed django-simple-friends as a package you are likely to have a project already, in this case you can just run the test
command of your projects. Example project is intended for developers.
Usage examples.
First, we're going to get two different users for our examples:
user1 = User.objects.get(id=1)
user2 = User.objects.get(id=2)
user1
requests friendship to user2
:
FriendshipRequest.objects.create(from_user=user1, to_user=user2, message='Friends?')
user2
accepts user1
request:
fr = FriendshipRequest.objects.get(from_user=user1, to_user=user2, accepted=False)
fr.accept()
user2
declines user1
request:
fr = FriendshipRequest.objects.get(from_user=user1, to_user=user2, accepted=False)
fr.decline()
If users are friends then return True
:
Friendship.objects.are_friends(user1, user2):
friends
will be a list with all id's from user1
friends:
friends = Friendship.objects.friends_of(user1).values_list('id', flat=True)