[Solved]-Django dynamic form, formsets with HTML array

2👍

From the discussion we started in the comments and your updated answer, I am unsure about the purpose of you customer_product table ? I will update my answer if I finally get it.

(It would actually seem to me that your customer_id field in customer_product model is redundant with the customer_id field in customer_product_order, making the table customer_product not actually usefull.)


To model a product ordering system, you could perhaps move the customer_id at the order level (from what I understand of your requirements, there a Customer has many orders, but and order has a single customer, which the current design fails to implement), giving you:

product_order
----------------------
id | product_id(ForeignKey) | order_id(ForeignKey) | quantity

order
-------
id | customer_id(ForeignKey) | invoice_number | delivery_date

If this model could suit your need, can you clarify what is the question you are facing ?


EDIT: I think the data modeling is slightly off, and it is not conveying the right message about what you are trying to achieve (making it complicated to help ;). In particular:

Customer hasand belongstomany products

Seems it could be a misconception: why would a Customer belong to a product ?
It seems more natural that the Customer would have a many-to-one relationship with Order instances. And a Order would have a many-to-one relationship with Products, potentially joined through an external table containing the quantity field (i.e., your CustomerProductOrder table).

That would give you this updated and simplified model:



    customer table
    --------------
    id | ...


    product table
    -------------
    id | description | ...


    order
    -------
    id | customer_id(ForeignKey) | person_placing_order | invoice_number | delivery_date


    order_content (~= customer_product_order)
    ----------------------
    id | order_id(ForeignKey)  | customer_id | product_id(ForeignKey) | product_quantity


Could you please explain why this more trivial design would not be fit for your purpose ? (Hoping that it will allow us to better understand your requirements)

👤Ad N

Leave a comment