This project is designed to showcase the completion of the Django machine test. It involves designing REST APIs for managing entities like Users, Clients, and Projects. The system includes many users and clients, where clients can have multiple projects, and projects can be assigned to many users.
- How to Run the Machine
- Database Design
- How to Run the Code
- Contributing
To run the Django project locally, follow these steps: Install Dependencies
First, clone the repository from GitHub to your local system: git clone https://github.com/nehapatil3071/Django-machine-test.git Navigate into the project directory:
cd Django-machine-test
It's recommended to run the project inside a virtual environment. Set up the virtual environment using the following commands:
python -m venv env
.\env\Scripts\activate
Install the required dependencies from requirements.txt:
pip install -r requirements.txt
Make sure you have MySQL installed and running. Update your database credentials in the Django project’s settings. Then, run the following commands to set up the database:
python manage.py makemigrations
python manage.py migrate
To start the Django development server, use the command:
python manage.py runserver
Now, the server should be running at http://127.0.0.1:8000/.
Download from MySQL Official Site Create a new database for your project Configure Django to Connect to MySQL: In your settings.py file, add your database configuration The database design includes three main entities:
- User: Represents the users of the system. Users are managed via Django's default admin system.
- Client: Represents the clients in the system. A client can have many projects.
- Project: Represents the projects associated with a client and assigned to multiple users.
The relationships between the entities: A Client can have multiple Projects. A Project can be assigned to multiple Users.
-
User Table: -Managed by Django's default user model.
-
Client Table: -Fields: id, client_name, created_by, created_at, updated_at
-
Project Table: -Fields: id, project_name, client_id, created_by, created_at, updated_at -Foreign keys: client_id (linked to Client), users (many-to-many relationship with User)
Now, run the migrations to set up your database schema:
python manage.py makemigrations
python manage.py migrate
Here’s how you can interact with the API endpoints.
-
Register a Client: -Endpoint: POST /api/clients/
-
Fetch Client Info: -Endpoint: GET /api/clients/
-
Edit/Delete Client Info: -Edit: -Endpoint: PUT /api/clients/{id}/
-
Delete: -Endpoint: DELETE /clients/{id}/ -Response: HTTP 204 No Content
-
Add New Project for a Client: -Endpoint: POST /api/clients/{id}/projects/
-
Retrieve Assigned Projects for Logged-In User: -Endpoint: GET /api/projects/
Feel free to fork this repository, make any changes, and submit a pull request. Make sure to pull the latest changes from the main branch before submitting any updates to avoid conflicts.