[Answered ]-Django Custom User Model

1👍

There are many ways to define a custom user model.

If you want to add one field you can basically extend the existing user model:

from django.contrib.auth.models import AbstractBaseUser

class MyUser(AbstractBaseUser):
    country = models.ForeignKey(Country, models.SET_NULL, blank=True, null=True)

And set AUTH_USER_MODEL in your settings module:

AUTH_USER_MODEL = 'yourapp.MyUser'

1👍

You would do that using the OneToOneField found here.

  1. Create an app (e.g. python manage.py startapp profile)
  2. Add the app to your settings.py file
  3. In your profile/models.py file, add the below example

from django.contrib.auth.models import User

 class Profile(models.Model):
   user = models.OneToOneField(User, on_delete=models.CASCADE)
   country = models.CharField('country', max_length=120)

Leave a comment