#13950: Add "post save" hook to ModelAdmin class
-------------------------------------------+--------------------------------
          Reporter:  3point2               |         Owner:  pandres
            Status:  reopened              |     Milestone:         
         Component:  django.contrib.admin  |       Version:  1.2    
        Resolution:                        |      Keywords:         
             Stage:  Unreviewed            |     Has_patch:  1      
        Needs_docs:  1                     |   Needs_tests:  1      
Needs_better_patch:  1                     |  
-------------------------------------------+--------------------------------
Changes (by 3point2):

  * status:  closed => reopened
  * resolution:  wontfix =>

Comment:

 I'll try explain the problem better.

 Let's start with the example I described above: the Invoice and
 InvoiceEntry models. I have registered the Invoice model with the admin
 and also registered the InvoiceEntry model as an inline (as you suggest).

 Let's say a user creates a new invoice, and adds several invoice entries
 using the inline forms. When the user clicks on "Save", there is no way to
 calculate the total of the invoice. This is why:

 * First, the invoice is saved. This calls the save_model method on the
 modeladmin, which calls the save() method on the Invoice model. At this
 point, none of the invoice entries have been saved yet, so it's not
 possible to calculate a total in save_model() or save()
 * The post_save signal is sent when save() completes. The invoice's
 invoiceentry_set manager still returns an empty list as the inlines have
 not been saved yet.
 * The inline invoice entries are now saved. At this point, it's no longer
 possible to hook into the save process to calculate the invoice's total.
 The only workaround would be to have each invoice entry update its parent
 invoice's total when it is saved, which will cause a lot of unnecessary
 save() calls on the invoice (one for each entry).

 My post_save hook allows the user to call a function *after* the inlines
 have been saved. This allows the total to be calculated using
 invoice.invoiceentry_set.all()

-- 
Ticket URL: <http://code.djangoproject.com/ticket/13950#comment:3>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to