I'm stuck in a design problem.
Imagine an order model and material model,
class Material(models.Model):
material_code = models.CharField(max_length=40)
standard_price = models.DecimalField()
class Order(models.Model):
customer = models.ForeignKey(Customer)
class OrderItems(models.Model):
order = models.ForeignKey(Order)
material = models.ForeignKey(Material)
price = models.DecimalField()
In my order detail view, I populate orderitems using inlineformset_factory(Order, OrderItems)
The behaviour I want is below:
If user wants to add more orderitems, I want to redirect user to material listing page, user chooses one or more materials and confirms, then I redirect him to order detail view again with newly added items.
I'm thinking of these to work, like django admin actions with intermediate page.
Before adding new orderitems to order, I also want to set orderitems price from material standard_price, this means I want to modify formsets values before adding it to orderitems.
The Question I want to ask here is, is there an easier way to achieve this, it seems, storing formset data to session and repopulating formset with new items wont be easy. I would consider another solutions to this problem.
I dont want the js solutions by the way, imagine a field on my order model, grandtotal, which I may calculate total item amount, with js solutions I may have to do calculation logic with js, user adds an item and change prices then I do the grandtotal calculation with js. This is what I want to avoid.