0

I have a Custom User Model extending the AbstractUser and it works fine. But now i want to create another Model that is extending my Custom User Model like this in models.py:

class CustomUser(AbstractUser):
    phone = models.CharField(max_length=10, null=False, unique=True)
    town = models.CharField(max_length=25, null=False)


class DeleveryPerson(CustomUser):
    code = models.CharField(max_length=10, null=False, unique=True)

The problem is that the table DeleveryPerson is created with just the field "code" when I expected it to also have fields coming from the CustomUser model. So how can i achieve that kind of inheretane between CustomUser and DeleveryPerson. Thk!

  • That's how inheritance in Django works - see the docs on [multi-table inheritance](https://docs.djangoproject.com/en/3.0/topics/db/models/#multi-table-inheritance). Django automatically creates a one-to-one field between `DeliveryPerson` and the `CustomUser` model. It might be better to do `class DeliveryPerson(models.Model):`, then add your own `one-to-one` field. – Alasdair Apr 23 '20 at 11:21
  • Note you've got a typo - change Del*e*very to Del*i*very – Alasdair Apr 23 '20 at 11:21
  • @Alasdair thank for the reply. I will use the automatically created one-to-one field – Daryl Mgbatou Apr 23 '20 at 15:51

0 Answers0