I need some ideas to solve the following issue, maybe with some design pattern or another approach in my current architecture.
My app's backend is entirely developed in Django framework and has five current models (no matter relationships between them):
- Product(id, product_name, product_category, product_code)
- Customer(id, customer_name)
- Account (id, account_code, account_name)
- City(id, city_name)
- User(id, email, user_name)
In first place, I need to add a new model to dynamically and easily create Transactions with any possible combination of the above models in the following way:
- Example 1: Transaction(id, product, customer, year, month, amount)
- Example 2: Transaction(id, account, year, month, amount)
- Example 3: Transaction(id, account, city, year, month, amount)
- Example N: Transaction(id, product, user, year, month, anount
As you can see, my Transaction model has a few static fields (year, month, amount), but the other fields depends on a random customization according the use case.
I've thought something like Transaction(id, dynamic_field_1, dynamic_field_2, dynamic_field_3, year, amount), but how can I make it dynamically? Is there some design pattern or properly way to do this?
In addition, I need that those fields have been validated from the previous models. For example:
Transaction(id, product, customer, year, month, amount):
- validate that product exist in the database
- validate that customer exist in the database
How can i make this approach?
Thank you!