[Answered ]-How can I insert data in two different models?

2👍

Well your models don’t make any sense at all. They really should be one model. you have not defined any relationship between any of the models. To do that you will have to add a OneToOneField or a ForeignKey. That effectively means you are having an extra column for each item of data. Totally redundant.

class Personinfo(models.Model):
    name = models.CharField(max_length=128)
    last_name = models.CharField(max_length=128)
    address = models.TextField()
    phone_number = models.CharField(max_length=128)
    hobbies =models.CharField(max_length=128)

    def __str__(self):
        return self.personame

This makes your life so much easier with simpler coding.

👤e4c5

0👍

your models don’t have class Meta , need to define the table name in class meta like :

class Meta: 
   managed = True
   db_table = 'tableName'

Then u need to override save function in personform

Leave a comment