I have an Order
(1) and OrderLine
(n) model, here order can have multiple order-lines. This is all run from inside the Django-admin, where the OrderLine
is setup as part of the inlines
on OrderAdmin(admin.ModelAdmin)
.
Simplified like this:
class OrderLine(admin.StackedInline):
pass
@admin.register(Order)
class OrderAdmin(admin.ModelAdmin):
inlines = [OrderLine]
I registered for the pre_save
and post_save
on on both models. Django calls these signals in the following order:
- Order | pre_save
- Order | post_save
- OrderLine 1 | pre_save
- OrderLine 1 | post_save
- OrderLine 2 | pre_save
- OrderLine 2 | post_save
- OrderLine n | pre_save
- OrderLine n | post_save
The issue I'm having is that I would like to change the order of the signals called, as follows:
- Order | pre_save
- OrderLine 1 | pre_save
- OrderLine 1 | post_save
- OrderLine 2 | pre_save
- OrderLine 2 | post_save
- OrderLine n | pre_save
- OrderLine n | post_save
- Order | post_save
Since I need to do a few calculations in each OrderLine
, and those results needs to be used in the Order
post. But the post signal
is already been called.
The only solution I see is to call my code on each OrderLine post signal
, which is a bit redundant, especially when you have many order-lines.
What would be the best / better way to tackle this?