This application, built with Django(with django-rest-framework), simplifies the collection process for remote farmland transactions. Designed for collectors, it serves two main functions: enrolling farmers and recording on-site transactions. Collectors use NFC/QR code-based cards provided to farmers during enrollment, streamlining product delivery and facilitating farmer-verified payments. The app ensures a straightforward and efficient experience for both collectors and farmers in the agricultural ecosystem.
- Installation
- Configuration
- Database Setup
- Usage
- API Endpoints
- Authentication and Authorization
- Testing
- Contributing
- License
- Contact Information
- Acknowledgments
-
Clone the repository:
git clone https://github.com/your-username/your-project.git
-
Navigate to the project directory:
cd your-project
-
Create a virtual environment:
python -m venv venv
-
Activate the virtual environment:
-
On Windows:
venv\Scripts\activate
-
On Unix or MacOS:
source venv/bin/activate
-
-
Install dependencies:
pip install -r requirements/local.ext
-
Create a
.env
file in the project root and configure environment variables:[app] ENVIRONMENT=local DEPLOYMENT=local ROOT_URL=http://localhost:8000 FRONTEND_ROOT_URL=http://localhost:3000 [dajngo] SECRET_KEY=************************** HASHID_SALT=************************** [database] DB_NAME=************************** DB_USER=************************** DB_PASSWORD=************************** DB_HOST=************************** DB_PORT=************************** REDIS_URL=redis://localhost REDIS_PORT=6379 [email] EMAIL_HOST=smtp.gmail.com EMAIL_HOST_USER=************************** EMAIL_HOST_PASSWORD=************************** [lib] AWS_ACCESS_KEY_ID=************************** AWS_SECRET_ACCESS_KEY=************************** AWS_STORAGE_BUCKET_NAME=**************************
-
Apply migrations:
python manage.py migrate
-
Create super user with email as username and password.
# for creating superuser python manage.py createsuperuser
-
Load currency details
# for loading currency details python manage.py runsript load_currencies
For running server locally
```bash
python manage.py runserver
Access the Django admin interface by navigating to http://localhost:8000/connect/admin/ and log in with the superuser credentials created earlier.
- Open your browser and go to http://localhost:8000/connect/v1 to view the available API endpoints.
- Use tools like curl or Postman to make HTTP requests to the API endpoints.
This Django DRF project uses token-based authentication. Follow these steps to obtain an authentication token:
-
Create a User Account:
Make a POST request to the
/api/auth/register/
endpoint with the required user registration data.Example using
curl
:curl -X POST -H "Content-Type: application/json" -d '{"username": "your_username", "password": "your_password"}' http://localhost:8000/api/auth/register/
-
Obtain an Authentication Token:
Make a POST request to the
/api/auth/token/
endpoint with the registered user credentials to obtain an authentication token.Example using
curl
:curl -X POST -H "Content-Type: application/json" -d '{"username": "your_username", "password": "your_password"}' http://localhost:8000/api/auth/token/
Save the received token for subsequent requests.
This project implements role-based access control:
-
Admin Users:
- Admin users have full access to all resources and endpoints.
-
Authenticated Users:
- Authenticated users (users with a valid token) have limited access based on their roles.
-
Anonymous Users:
- Anonymous users have limited or no access to certain resources.
Include the obtained token in the Authorization
header of your requests:
curl -H "Authorization: Token your_token_here" http://localhost:8000/api/some-protected-endpoint/
To run tests for the Django DRF project, use the following command:
python manage.py test
Running Specific Tests
python manage.py test <app_name>.tests.test_module
Then run the tests with coverage:
coverage run manage.py test
And generate a coverage report:
coverage report -m
We welcome contributions from the community! If you would like to contribute to this Django DRF project, please follow the guidelines below:
- Before submitting a new issue, please check the issue tracker to see if the issue has already been reported or discussed.
- When creating a new issue, provide a clear and detailed description, including steps to reproduce if applicable.
- If you're reporting a bug, include information about your environment (Django and DRF versions, database, operating system, etc.).
-
Fork the repository:
git clone https://github.com/your-username/your-project.git cd your-project git fork
-
Create a new branch:
git checkout -b feature-branch
-
Make your changes and commit:
git add . git commit -m "Your descriptive commit message"
-
Push to the branch:
git push origin feature-branch
-
Submit a pull request:
- Go to the Pull Requests tab in the repository.
- Click on "New Pull Request" and select the branch you just pushed.
-
Follow the pull request template and provide necessary details.
- Follow the PEP 8 style guide for Python code.
- Write meaningful commit messages and keep the commit history clean.
- Ensure that your changes do not break existing tests.
- If you're adding a new feature, include relevant tests.
- Run the test suite locally before submitting a pull request.
Please note that this project follows the Contributor Covenant Code of Conduct. By participating, you are expected to uphold this code. Report any unacceptable behavior to [maintainer email].
- The project maintainers will review your pull request and may provide feedback or request changes.
- Once the changes are approved, the pull request will be merged.
Thank you for contributing to our Django DRF project! If you have any questions or need further assistance, feel free to reach out to [maintainer email].
If you have any questions, suggestions, or feedback, feel free to reach out:
- Maintainer: [Your Name]
- Email: [your.email@example.com]
You can also open an issue on the issue tracker for bug reports, feature requests, or general discussions related to the project.
Follow us on Twitter: @your_project_handle
We appreciate your interest and contributions to our Django DRF project!