I am trying to generate a printable report when saving objects for the
first time. This is easy enough except I can't easily access related
objects by overriding save() as they are not saved yet, nor are they
available within the save() method.
The new ModelAdmin.save_related() in Django 1.4 method seems to have
been created for just my need. The docs say: "Here you can do any pre-
or post-save operations for objects related to the parent. Note that
at this point the parent object and its form have already been saved."
From what I read this seems perfect for my use case.
I tried overriding the method as follows:
def save_related(self, request, form, formsets, change):
if not change:
# Generate and send report only if creating for first time
parent_obj = form.instance
import pdb; pdb.set_trace();
1) At that point when I look into the database I don't see the saved
parent object? This seems to contradict the docs.
2) I can access cleaned data from the formsets, but is there an easy
way to simply get the related instances as I would with
parent.child_set.all(). This would make my life much easier as I have
written the code already to print a LaTeX report from any Django model
(by looping _meta.fields approach).
I would appreciate any help.