How to save other data after form_valid action in django UpdateView?
<p>I have successfully changed a particular field <code>net</code> in my object based on the quantity <code>qty</code> field with the following code.</p>

<pre><code>class OrderDetailsProductEdit(UpdateView):
    model = OrdersPlaced
    fields = ['qty']
    template_name = 'backend/order-details-product-edit.html'
    success_url = '../../../'

    def form_valid(self, form):
        form.instance.net = form.instance.qty * form.instance.price
        # order = Order.objects.get(pk=self.kwargs['order_id'])
        # subtotal = OrdersPlaced.objects.filter(order=order).aggregate(Sum('net'))['net__sum']
        # order.subtotal = subtotal
        # order.save()
        return super(OrderDetailsProductEdit, self).form_valid(form)
</code></pre>

<p>However, I am also trying to change the data in ANOTHER model. To be precise, I want the summation of all <code>net</code> values of a query and update the <code>subtotal</code> field in another table.</p>

<p>Please notice the commented out lines under <code>def form_valid</code>. I have no confusion that these lines work, but I need them to execute AFTER the current model is saved, as those are dependent on the value of the current model.</p>

<p>I don't find any errors other than that the <code>subtotal</code> field in ANOTHER model is calculated BEFORE the <code>net</code> field in the current model is saved. Thus, the total is a wrong answer.</p>

<p>What am I doing wrong?</p>