[Answered ]-Is it possible to create related objects on parent creation automatically in Django?

1👍

✅

You can overwrite the save method of the models to do what you want like this

from django.db import models

class Blog(models.Model):
    name = models.CharField(max_length=100)
    tagline = models.TextField()

    def save(self, *args, **kwargs):
        do_something()
        super().save(*args, **kwargs)  # Call the "real" save() method.
        do_something_else()

See more in the docs here

Leave a comment