In this part, we focus on creating the Users app and all the models related to the User Profile, Authentication, Friends Model and so on.

Social Media App

Image by Freepik

So, in the first part of the tutorial, we learnt how to set up our project and setup various authentication backends and other details regarding various installs and app setups needed in the settings file.

If you have not read the first part yet, make sure to complete it first before moving forward as we would be building on top of that in this part.

There would be lots of terms which you may be encountering for the first time, like you may have heard about views or models for the first time, so I would be briefing about them a little. I cannot talk about those in details because our focus is not to teach you basic concepts, but to build a social media website. So, I would be linking to good resources for you to refer to those specific topics and then continue with this tutorial.

So, let’s go ahead and build the Users app we created in the last tutorial. We will start by creating the models first.

models.py

In this python file, we will define our models. As you might already know, models are defined to tell Django what to save in the database and to define the relationship between different models and what characteristics they have.

To learn more about Django models, do visit this amazing tutorial on models by Mozilla Developers. It talks about models in depth.

After you are comfortable with how models work, you can proceed to make models for our social media website.

So, we will have two models — one for the user’s profile and the other for Friend Requests.

We will need to import many things before we begin writing the models. We will be using the Default User model of Django to have One to One Relationship with our Profile Model i.e. each user will have one profile.

We are also using _autoslug _to automatically produce slugs for the URLs based on the username.

For e.g.: A user with the name Tom would have slug as _tom. _This will help us make meaningful URLs as users/tom will lead to Tom’s profile rather than numbers.

#django #website #python #bycetutorial #web

Build a Social Media Website with Django 
1.45 GEEK