add fields to django user model code example

Example 1: django import user

from django.contrib.auth.models import User

Example 2: django user fields

# Django User Model Fields
username
first_name
last_name
email
password
groups
user_permissions
is_staff
is_active
is_superuser
last_login
date_joined

Example 3: import abstractuser

from django.contrib.auth.models import AbstractUser

Example 4: django add user to group

from django.contrib.auth.models import Group, User
 
g = Group.objects.get(name='My Group Name')
users = User.objects.all()
for u in users:
    g.user_set.add(u)

Example 5: adding extra fields to user model django

class UserProfile(models.Model):
   user = models.OneToOneField(User)
    ...#the fields you need