0

I'm currently implementing a solution using django admin, it allows users to define in the db a product, and then custom attributes and details, more details may be aggregated by a common attribute, this allows me to query with ajax a custom view that returns some JSON data to build automagically the form fields that I need directly in the same formset view (manipulating the DOM).

The current DB design follows this schema: Catalog(name, description, photo) Product(rel_catalog, name, base_price, photo, manufacturer_email) ProductDetail(rel_product, rel_attribute, percentage_price, fixed_price) ProductAttribute(rel_product, name, description)

As you may see I have a catalog, where there can be more products, a lot of details per product, aggregated by attributes. Then I simple show by default the Catalog, then the select with all available products for that catalog, then, choosing the right Product, I obtain the complete form (each row has a label with ProductAttribute.name and a select with related ProductDetail).

All works pretty dam good, but I also need to store this references in the DB when someone completes the form (making an order with choosen products). This forms are displayed as StackedInline (the ModelAdmin is for the Order). I don't know how many options there may be per product so I was thinking to use this design to track orders: Order(customer, status, notes, tot_price, inserted_by) OrderItem(rel_order, catalog, product, unit_price)

But I don't know how to store the dynamic added inputs... I was thiking to implement OrderItemProperty(rel_orderitem, rel_productdetail, rel_productattribute) to store each single input... but how do I loop over this unknown fields?

Maybe do you suggest a better design?

If you need more code just ask for it and I'll reply with a pastebin link. Thankyou.

2
  • Please specify what user (javascript) event do you mean for 'when someone completes the form'? User presses a button, some field looses the focus? Commented Dec 24, 2011 at 13:35
  • When someone clicks on the "Save" button submitting the form data with dynamically added ajax fields (that must be storen in some way). Commented Dec 24, 2011 at 17:02

1 Answer 1

1

Finally I got a working solution,

I've created a custom view, overriding the default "add/" view, this way I can customize whatever I want to and I can read the POST data handling each validation, putting then the data in the right model.

Sign up to request clarification or add additional context in comments.

Comments