working on models #2
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR implements key backend components for the mlimizone marketplace including the data models and role-based REST API access control.
Perhaps answering the following questions will help create a good description:
This is a backend implementation for an mlimizone marketplace system using Django and Django REST Framework. It includes custom data models (users, crops, produce listings, carts, orders, payments, market prices, SMS logs) and a role-based access control system that controls API access and permissions for different user roles such as farmers, wholesalers, and admins.
Role-based access control (RBAC) is essential to:
Secure sensitive data by ensuring users only access data relevant to their role.
Enforce business rules, e.g., only farmers can create produce listings, wholesalers manage their carts and orders, and admins control crop and price data.
Avoid unauthorized modifications or deletions of data, such as preventing cart deletions.
By defining custom Django models that capture the necessary entities with proper relations.
Implementing Django REST Framework ModelViewSets for each model to provide standard API CRUD operations.
Using custom permission classes that inspect the authenticated user’s role and ownership on each object to control access and edits.
Overriding viewsets’ querysets to filter data based on the requesting user’s role and ownership.
Special permissions for admin users to have full access where appropriate but restricting general users to read-only on sensitive data.
Allowing authentication via both email through a custom user model and authentication backend, increasing flexibility and usability.
Please delete options that are not relevant.
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
Checklist: