I'm building my own e-commerce system from scratch using the django-rest-framework.
Here is a description of my system architecture:
Db format = PostgresSQL
One Account has many LineItems (aka CartItems).
One LineItem has one Account (FK), one Product (FK)
One Account has many Orders
LineItem Fields:
- Account FK
- Product FK
- Quantity
- Price (Serializer method field to factor in any discounts (range 0-1) specified the product model).
My Issue lies with the account being able to create an order.
I have identified two ways so far:
1) Modify the LineItem Model by adding the following fields:
- IsMountedForOrder (for buy now purposes) - BooleanField
- Order (Foreign Key)
Constraint: The LineItems Model becomes overburdened with Foreign Keys and relationships - it seems like going to be a hindrance from a DB management standpoint. Do correct me if I'm wrong.
2) Create an OrderItem Model (One Order has Many OrderItems)
Fields:
- Order FK
- Product FK (Parsed from owned LineItems)
- Quantity (Parsed from owned LineItems)
- Price (Parsed from owned LineItems)
and upon creation of a successful order, the lineItems will be deleted.
Constraints: There is a duplication of Data for a short duration and seems like unnecessary computation - therefore adding latency to the service.
I would appreciate any suggestions in how I can achieve an efficient order creation method. Either by modifying the two methods or identifying any architecture flaws I might have overlooked. Thank you!