Package: the-social-network
The Social NetworkThe package "The Social Network" is a django base backend core element for any possible social network you can think of. You can easily create clones for all popular social networks.InstallationMinimum requierments are:Python>= 3.9Django>= 3.2.9Pillow>= 8.4.0djangorestframework>= 3.12.4Intallation can be done bypiplikepip install the-social-networkor download manuel onPypi.How to useIf you not have already created a django python project,createit at first in a new directory with the commanddjango-admin startproject mysiteThis will create amysitedirectory in your current directory.Open themysitedirectory and open thesettings.py.
Add'the_social_network'toINSTALLED_APPSand save the file.Next open the urls.py and add the following lines to yoururlpatternsurl(r'^authentication/', include('the_social_network.urls.authenticationUrls')),url(r'^accounts/', include('the_social_network.urls.accountUrls')),url(r'^search/', include('the_social_network.urls.searchUrls')),url(r'^contents/', include('the_social_network.urls.contentUrls'))Now everything is ready to run django withthe-social-network.
Create the database withpython manage.py migrateand start the server withpython manage.py runserverthe default django information page should showup if you openhttp://127.0.0.1:8000/in your browser.Request API for the URLsIn all requests (except for the request ofauthentication/register/or/authentication/login/) you need to send the authentification token inside the header.
For authorization use the header name "Authorization" and the value "Token "AuthenticationPOST url: ".../authentication/register/"Register a userRequestbody:{"username":"username","password":"password","email":"email"}Responsebody:{"token":"token"}POST url: ".../authentication/login/"Login a userRequestbody:{"username":"username","password":"password"}Responsebody:{"token":"token"}POST url: ".../authentication/logout/"Logout a userRequestbody: NoneResponsebody: NoneSuccess: HTTP/200GET url: ".../authentication/validate/"Validate a tokenRequestbody: NoneResponsebody: NoneSuccess: HTTP/200AccountGET url: ".../accounts/show/<user_id>/"Show a public userRequestbody: NoneResponsebody:[{"user":{"id":...,"username":...,"email":...,"date_joined":"..."},"image":"...","biography":"...","related_by":[],"related_to":[],"statements":[]}]GET url: ".../accounts/show/own/"Show the own userRequestbody: NoneResponsebody:[{"user":{"id":...,"username":...,"email":...,"date_joined":"..."},"image":"...","biography":"...","related_by":[],"related_to":[],"statements":[]}]GET url: ".../accounts/show/all/"Show all public usersRequestbody: NoneResponsebody:[{"user":{"id":...,"username":...,"email":...,"date_joined":"..."},"image":"...","biography":"...","related_by":[],"related_to":[],"statements":[]},...]PUT url: ".../accounts/update/"Updates the own account. Only "Biography" and "Image" are allowed to be updated.Requestbody:{"biography":"...","file":"..."}Responsebody: NoneSuccess: HTTP/200PUT url: ".../accounts/follow/<user_id>/"Follow a userRequestbody: NoneResponsebody: NoneSuccess: HTTP/200PUT url: ".../accounts/unfollow/<user_id>/"Unfollow a userRequestbody: NoneResponsebody: NoneSuccess: HTTP/200PUT url: ".../accounts/operation/add/statement/"Add a statement to the own accountRequestbody:{"input":"<statement>""reactions":{"to":<reaction_to_a_statement_id>,"relation":<"attack"or"support">}<---optional}Responsebody:{"id":...,"author":{"user":{"id":...,"username":"..."},"image":"..."},"content":"...","tagged":[],"mentioned":[],"created":"...","relation_to_parent":...}Success: HTTP/200ContentsGET url: ".../contents/statements/get/<statement_id>/"Get a statementRequestbody: NoneResponsebody:[{"id":...,"author":{"user":{"id":...,"username":"..."},"image":"..."},"content":"...","tagged":[],"mentioned":[],"created":"...","relation_to_parent":...,"reactions":[]}]GET url: ".../contents/statements/with/hashtag/"Get all statements with a hashtagRequestbody: NoneQueryparameters: "?q="Responsebody:[{"id":...,"author":{"user":{"id":...,"username":"..."},"image":"..."},"content":"...","tagged":[],"mentioned":[],"created":"...","relation_to_parent":...,"reactions":[]},...]GET url: ".../contents/statements/feed/"Get all statements of the accounts that are followed by the userRequestbody: NoneResponsebody:[{"id":...,"author":{"user":{"id":...,"username":"..."},"image":"..."},"content":"...","tagged":[],"mentioned":[],"created":"...","relation_to_parent":...,"reactions":[]},...]GET url: ".../contents/statements/feed/pagination"Get statements of the accounts that are followed by the userRequestbody: NoneQueryparameters: "?page=<page_number>&size=<number_of_statements_per_page>"
Responsebody:{"total":...,"data":[{"id":...,"author":{"user":{"id":...,"username":"..."},"image":"..."},"content":"...","tagged":[],"mentioned":[],"created":"...","relation_to_parent":...,"reactions":[]},...]}GET url: ".../contents/trending/hashtag/"Get all trending hashtags which are most used in statementsRequestbody: NoneReponsebody: ++++++ TODO:  Setting of a hashtag not clear ++++++SearchGET url: ".../search/"Searchs for a user or hashtagRequestbody: NoneQueryparameters: "?q=<search_query>&filter=<"user" or "hashtag">"Responsebody:{"accounts":[{"user":{"id":...,"username":"...",},"image":"..."},...],"hashtags":[{"id":...,"tag":"..."},...]}Core Database structureThe project requieres the base authentication database structure from django and extends it with the following tables:the_social_network_accountwith  
user_id: int as primary key and foreign key to django auth_user  
image: varchar(100) -> default image is 'account/default/Argunaut.png', it's not inside the package and default path to store image is "account/images"
biography: varchar(1000)the_social_network_statementwith  
id: int as primary key  
author_id: int as foreign key to the_social_network_account  
content: varchar(120)  
created: datetimethe_social_network_accounttaggingwith  
id: int as primary key  
created: datetime  
account_id: int as foreign key to the_social_network_account  
statement_id: int as foreign key to the_social_network_statementthe_social_network_hashtagwith  
id: int as primary key  
tag: varchar(30)  
created: datetimethe_social_network_hashtagtaggingwith  
id: int as primary key  
created: datetime  
hashtag_id: int as foreign key to the_social_network_hashtag  
statement_id: int as foreign key to the_social_network_statementthe_social_network_reactionwith  
id: int as primary key  
created: datetime  
vote: small uint  
child_id: int as foreign key to the_social_network_statement  
parent_id: int as foreign key to the_social_network_statementthe_social_network_relationshipwith  
id: int as primary key  
created: datetime  
from_account_id: int as foreign key to the_social_network_account  
to_account_id: int as foreign key to the_social_network_account