This is my second blog about my Instagram project and till now I am confronted with many questions and problems, two such problems are how to store the user profile and how to implement the "follow" feature of Instagram. In this blog, I will describe the prior problem
To any social networking site, the most important component is its end user. The user has his/her important role in the functioning of a social networking site and that part doesn't need a description. Till now, for all my mini projects, whenever the user was required I have used the User model of the Django framework, but this is something different. An SNS(social networking site) always has a user profile which holds a wide variety of information such as status, display picture, email, links to other sites etc but the Django's User model has only some fields namely first name, last name, email, username, password. Only this handful of information cannot account for the user profile. I know many of you will suggest me to create my own user model, but if I do so, I may not be able to use the built-in functions for the user in Django's libraries such as login, logout, authenticating etc. Implementing all of them might be a hell of a task for a beginner like me. So how do we solve this problem??
Like any other programmer, when I wasn't able to come up with a solution on my own I seek help. In such scenarios, Google and StackOverflow are undoubtedly programmers best friend. While exploring these websites, I came across many solutions to this problem such as extending the User model, having a one to one relation from a different class etc. Out of all the solutions, the one solution, that I thought will fit my requirements was, having a different model for the user profile and having a one to one relation of the profile with User model of Django.Confusing right? Let me simplify things further for you. We have a user table that stores the necessary credential details of the user. For all other details which we want to store for our user, we can maintain a different table that stores other data such as the display picture, email, status, gender etc This profile table will have an attribute user which would have a one to one relationship with the user in the Django's User table. To those who have no idea what One-to-one relation is, its similar to the Foreign key but the foreign key is more of a Many-to-One relation. A foreign key can be used in the cases where many records in one model are related to one of the records in the other table, on the other hand, a One-to-One relation is the one where one record in one table is related to only one record in another table. Any user from the Django's user table will have only one profile in the profiles table. Hence this was the solution which I think best suited my requirements
I will discuss the next problem which I faced in the next blog and believe me that is much more interesting than this problem as on solving that we will be able to replicate the "follow" feature of the Instagram. So stay tuned
To any social networking site, the most important component is its end user. The user has his/her important role in the functioning of a social networking site and that part doesn't need a description. Till now, for all my mini projects, whenever the user was required I have used the User model of the Django framework, but this is something different. An SNS(social networking site) always has a user profile which holds a wide variety of information such as status, display picture, email, links to other sites etc but the Django's User model has only some fields namely first name, last name, email, username, password. Only this handful of information cannot account for the user profile. I know many of you will suggest me to create my own user model, but if I do so, I may not be able to use the built-in functions for the user in Django's libraries such as login, logout, authenticating etc. Implementing all of them might be a hell of a task for a beginner like me. So how do we solve this problem??
Like any other programmer, when I wasn't able to come up with a solution on my own I seek help. In such scenarios, Google and StackOverflow are undoubtedly programmers best friend. While exploring these websites, I came across many solutions to this problem such as extending the User model, having a one to one relation from a different class etc. Out of all the solutions, the one solution, that I thought will fit my requirements was, having a different model for the user profile and having a one to one relation of the profile with User model of Django.Confusing right? Let me simplify things further for you. We have a user table that stores the necessary credential details of the user. For all other details which we want to store for our user, we can maintain a different table that stores other data such as the display picture, email, status, gender etc This profile table will have an attribute user which would have a one to one relationship with the user in the Django's User table. To those who have no idea what One-to-one relation is, its similar to the Foreign key but the foreign key is more of a Many-to-One relation. A foreign key can be used in the cases where many records in one model are related to one of the records in the other table, on the other hand, a One-to-One relation is the one where one record in one table is related to only one record in another table. Any user from the Django's user table will have only one profile in the profiles table. Hence this was the solution which I think best suited my requirements
I will discuss the next problem which I faced in the next blog and believe me that is much more interesting than this problem as on solving that we will be able to replicate the "follow" feature of the Instagram. So stay tuned
Comments
Post a Comment