是否可以在 django 管理表单上编辑实际对象之前保存相关对象?
例如:
在models.py
class Parent(model.Model):
pass
class Child(model.Model):
parent = models.ForeignKey(Parent)
@receiver(post_save,sender = Parent)
def notify_parent_save(sender, instance=None, **kwargs):
print "Parent save"
@receiver(post_save,sender = Child)
def notify_child_save(sender, instance=None, **kwargs):
print "Child saved"
在admin.py
class ChildInline(admin.TabularInline):
model = Child
extra = 1
class ParentsAdmin(admin.ModelAdmin):
inlines = [ChildInline]
admin.site.register(Parent,ParentsAdmin)
现在,在 django admin 中,如果我保存父对象,它将在控制台上输出。
Parent save
Child save
我需要以相反的顺序发生这种情况:
Child save
Parent save