🌱💧A Django-based application to manage hydroponic systems with full CRUD capabilities, sensor data management, and user authentication.
Django Hydroponics Management is a web application built with Django and Django REST Framework that allows users to manage hydroponic systems and sensor data. It provides endpoints for CRUD operations on hydroponic systems and sensor measurements, user authentication, and more.
Follow these steps to set up and run the application locally:
-
Clone the repository:
git clone https://github.com/filipwroblewski/django-hydroponics-management.git
-
Navigate to the project directory:
cd django-hydroponics-management
-
Create a .env file in the root directory and add the following variables:
SECRET_KEY=<your_secret_key> POSTGRES_DB=<your_database_name> POSTGRES_USER=<your_database_user> POSTGRES_PASSWORD=<your_database_password> POSTGRES_HOST=db
-
Replace
<your_secret_key>
with value, generated byfrom django.core.management.utils import get_random_secret_key print(get_random_secret_key())
Note: You should have your django installed.
-
Replace
<your_database_name>
,<your_database_user>
, and<your_database_password>
with your own values.
Note: The
.env
file is used to store environment variables that are specific for local development environment. This file should not be committed to version control. The.env
should be listed in.gitignore
file. -
Make sure Docker and Docker Compose are installed on your machine. You can download Docker from the official Docker website.
Once everything is set up, you can run the application with Docker using the following commands:
-
Build and start the Docker containers:
docker-compose up --build
This command will:
- Build the Docker images as specified in the Dockerfile.
- Start the services defined in docker-compose.yml.
Example output
If you have not built yet, use
docker-compose up --build
. If you have already built, usedocker-compose up
.docker-compose up --build
Example output
-
Apply database migrations:
After the containers are up and running, create and apply the Django migrations to set up your database schema:
-
Make Migrations
docker-compose exec web python manage.py makemigrations
Example output:
No changes detected
-
Migrate
docker-compose exec web python manage.py migrate
Example output
-
-
Create a superuser:
To create a Django superuser for accessing the admin interface, run:
docker-compose exec web python manage.py createsuperuser
Example output
-
Access application:
Description URL Access application http://localhost:8000 Access Django admin interface http://localhost:8000/admin
Hydroponics Management API allows you to interact with hydroponic systems and measurements. To explore and test the API endpoints, you can use Api documentation interface using Swagger.
You can access the Swagger UI at http://127.0.0.1:8000/api-docs/. This interface provides information about each API endpoint, including the available methods, parameters, and expected responses. You can also use it to execute API requests directly from your browser, making it easier to understand how to interact with the API effectively.
To get started with the API:
- Ensure your server is running.
- Navigate to http://127.0.0.1:8000/api-docs/.
- Use the interactive documentation to explore the available endpoints and try out API requests.
To test API you can run:
docker-compose exec web python manage.py test
Example output:
Found 52 test(s).
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
....................................................
----------------------------------------------------------------------
Ran 52 tests in 33.261s
OK
Destroying test database for alias 'default'...
You can find tests here
To stop the application, run:
-
Press
ctrl + C
Example output:
Gracefully stopping... (press Ctrl+C again to force) [+] Running 2/2 - Container django-hydroponics-management-web-1 Stopped 0.8s - Container django-hydroponics-management-db-1 Stopped 0.7s canceled
-
Remove containers:
docker-compose down
Example output:
[+] Running 3/3 - Container django-hydroponics-management-web-1 Removed 0.0s - Container django-hydroponics-management-db-1 Removed 0.0s - Network django-hydroponics-management_default Removed 0.8s
This command will stop and remove the containers, but the data in the PostgreSQL volume will be preserved.
This project is licensed under the MIT License.