0% found this document useful (0 votes)
2 views2 pages

Python Challenge.docx

The document outlines the design and implementation of a Django API for a social media platform, featuring models for User, Post, and Comment. It specifies required API endpoints for user management, post creation, and commenting, all of which must include authentication and optimized ORM queries. Additionally, it includes submission requirements, evaluation criteria focusing on correctness, code quality, optimization, and testing.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
2 views2 pages

Python Challenge.docx

The document outlines the design and implementation of a Django API for a social media platform, featuring models for User, Post, and Comment. It specifies required API endpoints for user management, post creation, and commenting, all of which must include authentication and optimized ORM queries. Additionally, it includes submission requirements, evaluation criteria focusing on correctness, code quality, optimization, and testing.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 2

Python Challenge

Design and implement a Django API for a social media platform that allows users to create posts,
follow other users, and comment on posts.

The API should include (but may not be limited to) the following models:

User: Represents a user on the platform. Include fields for username, email, password, and
followers/following relationships.

Post: Represents a user's post. Include fields for the author (foreign key to User model),
content, and timestamps (date created).

Comment: Represents a comment on a post. Include fields for the author (foreign key to User
model), post (foreign key to Post model), and content.

Implement the following endpoints:

● GET /api/users/: Retrieve a list of all users.


● GET /api/users/{id}/: Retrieve details of a specific user. Including number of total posts,
number of total comments, followers and following.
● POST /api/users/{id}/follow/{id}: Set first id user as follower of second id user.
● POST /api/users/: Create a new user.
● GET /api/posts/: Retrieve a list of all posts ordered from newest to oldest from all users,
with pagination and filters. The filters to implement are: author_id, from_date, to_date.
None of the filters is compulsory. The pagination should be achieved with the following
parameters: page_size (default = 20), page_number (default = 1)
● GET /api/posts/{id}/: Retrieve details of a specific post with it's last three comments
included and the information of it's creator. ver timestamp
● POST /api/posts/: Create a new post.
● GET /api/posts/{id}/comments/: Retrieve all comments for a specific post.
● POST /api/posts/{id}/comments/: Add a new comment to a post.

Ensure that all endpoints require authentication. Implement token-based authentication using
Django's built-in authentication system.

Optimize the ORM queries to minimize the number of database hits and improve performance.

Implement appropriate indexing and constraints on database fields to optimize query


performance.

Optimize complex queries involving multiple models and relationships.

Write unit tests to ensure the API endpoints and ORM queries are functioning correctly.

Use Django REST framework for building the API.

1/2
Submission:
Provide the source code of your Django project, including all necessary files and folders.

Include a README file with instructions on how to set up and run the project.

Briefly explain the optimizations applied to the ORM queries and any challenges faced during the
implementation.

Evaluation Criteria:
Correctness: Verify that the API endpoints are functioning as expected and that the ORM queries
are optimized.

Code Quality: Assess the overall code organization, adherence to best practices, and proper use
of Django REST framework.

Optimized Queries: Evaluate the effectiveness of the applied optimizations and their impact on
query performance.

Testing: Check the presence of unit tests and their coverage of the API endpoints and ORM
queries.

2/2

You might also like