Creating a Customer transaction history, within the customer.

Hello.

I am developing something and I have difficulty with a part of the Model, I registered a client and within this client, I would like to register his credit and debit information (transaction history of this client).
He will borrow money and I need to register it, inside the client, so I need to enter the information of how much money he acquired with us and register manually, and every time he makes a payment, I need to register inside him too to see how much remains to be paid.

I have no idea how to do this, I need to save an information inside another information and go to feed it manually.

See scope below


Here I am already inside the registered customer, so inside the registered customer, I have the information below, to insert the description and value, and clicking on ‘include’ will add the information, for the direct customer (below), having all the history saved there, to be consulted in the future.

You have (at least) two ways of approaching this, and to some degree, what you’re going to want to do with this data over time may determine which of the two are better for your application.

  1. The Relational Database way of doing this is to create another table for transactions and have those transactions related to the client with a Foreign Key. (If you’re not used to working with foreign keys, I strongly suggest you work your way through the Django Tutorial before proceeding. The analogy works between the two applications if you consider the tutorial’s Question model to be your Client and the Choice model to be your Transactions.

  2. The non-relational way would be to use either an ArrayField (generally assuming Postgresql is the database) or a JSONField to store serialized versions of the transactions.
    Note: I typically don’t recommend doing this. Going this route makes it very easy to paint yourself into a corner that won’t be easy to work your way out of. There are good reasons why the traditional / relational approach identified above exists.

Ken