2

How to Modify the default Django user table and the custom user table should consist of the 'first name','last name', 'gender', 'Email(Primary Key)', 'phone number' fields. How to do this? forms.py

class UserForm(ModelForm):
    class Meta():
        model= User
        fields = 'First_name','Last_name','Gender', 'email','Phone_number'
kumar
  • 53
  • 2
  • 8
  • 2
    Does this answer your question? [Extending the User model with custom fields in Django](https://stackoverflow.com/questions/44109/extending-the-user-model-with-custom-fields-in-django) – suayip uzulmez Jan 03 '20 at 16:30

1 Answers1

3

You need to create custom model to extend Django user model. look in the documentation

Example with your fields

from django.contrib.auth.models import User

class ExtendedUser(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE)
    First_name = models.CharField(max_length=100)
    Last_name= models.CharField(max_length=100)
    Gender = models.CharField(max_length=100)
    email = models.CharField(max_length=100)
    Phone_number = models.CharField(max_length=100)

and then use it in your form

weAreStarsDust
  • 2,634
  • 3
  • 10
  • 22