I want to create a follow/follower system

I have started a Django project (complete newbie) and it is a social network. I am trying to implement a system of being able to follow users. I have tried so many different alternatives I am completely confused! Can anyone recommend documentation about implementing a basic follow system in Django?

Whatever information I have found people are using the id or pk in the urls.py file but I am using slug for my urls and I think that is contributing to my error.

I have code setup which isn’t working and I didn’t want to just dump all my code here. What I first wanted to ask is whether there is any documentation or whether anyone has managed to set up a follow system that I could use/learn from to help me. Thanks in advance.

There have been a handful of threads here in the forum of other people working their way through that type of system. Most of them include significant sections of code.

There are multiple ways of doing this, it’s up to you to decide which path you’re going to take, and your choice is going to depend upon exactly what you want to do.

For example, a Person could follow another Person. Or, you may want to have a Person follow a Group. Or, you may want a Person to be able to follow an individual Post. Each of these choices (or a combination thereof) may have an effect on the implementation.

So what I would suggest:

  • Browse some of the other discussions here
  • Define, as precisely as you can, what exactly you mean by a “follow/follower” system. This include enumerating the actions to be performed.
  • Define your models to support that functionality.
  • Implement that functionality in your views.

Thank you Ken
I had a search but couldn’t find anything relevant but maybe I was in the wrong section. I will try again.

Right now, all I want is for one user to follow another and be able to unfollow them. On their profile will show number of followers and number of people they follow. A little like Instagram.

Thanks again. Will start searching.

I searched for “following follows” and found these as some starting points:

(I seem to remember some other threads along these lines but these should help get you started - or at least give you some ideas.)

1 Like

Appreciate that. I am using the same model as the last one so hopefully I might be able to get something from it (after a break and a cup of tea!) Otherwise I will add my code and see if direct help is better.

If you don’t feel like doing all of the model relationships yourself, you might check out our django-friendship library.

It’s not the most amazingly maintained of our third-party packages, but the models work great for Twitter style one-way following as well as FB style mutual friendship situations.

2 Likes

Thank you. I looked so hard for something that was already available so I didn’t have to go through writing it. That plugin would have been so useful!!!

I have added a new post with my code and Ken has kindly looked through it so hoping it will work soon.

Then I move on to adding comments and getting my infinite scroll to work. At which point I am done. Will be great to get to that finish line. These three things have taken more time to fix than actually putting the site together :crazy_face:

1 Like

May I humbly suggest that this package be tagged under the “social” category on djangopackages.org? My (admittedly cursory) search did not find it.

1 Like