[Fixed]-Django — how to construct and initialize a complex model object with many depenencies

1👍

You may want to look at django signals https://docs.djangoproject.com/en/1.8/topics/signals/. Put a signal on the post_init signal for this model and have it create and associate the child models.

Here’s a list of signals https://docs.djangoproject.com/en/1.8/ref/signals/

So for example:

@reciever(post_init, sender=ParentClass)
def on_parent_class_create(sender, **kwargs):
    instance = kwargs['instance']
    instance.child1 = ChildClass()
    etc...
    ...
👤aeros

Leave a comment