I have 2 Models in Django. ModelA and ModelB. Here is the code for both these models.(This is just example code.)
class ModelA(models.Model):
# Single Insert
name=model.CharField(max_length=100)
class ModelB(models.Model):
# Multiple Insert
model_a=models.ForeignKey(ModelA,on_delete=models.CASCADE)
address=models.CharField(max_length=250)
Now how can i insert data in both these models using a single Database Query(i.e Database should be hit only once) using ORM in Django.More specifically is it possible to do this via Django REST serializers cause it can handle the CRUD operations in an optimized manner.
I know that i can do this via multiple serializers but that will lead to the databse getting hit multiple times or i can also do this via stored procedures in MySQL.