# Custom Field User Model

To add extra fields to the default Django User model, you can create a new model that inherits from the built-in User model and adds the extra fields you need. Here's an example:

### Model

```python
from django.contrib.auth.models import AbstractUser
from django.db import models

class CustomUser(AbstractUser):
    # Add extra fields here
    phone_number = models.CharField(max_length=20)
    address = models.CharField(max_length=200)

```

### Settings.py

```python
AUTH_USER_MODEL = 'your_app.CustomUser'
```

### Make Migrations And Migrate

```bash
python manage.py makemigrations
python manage.py migrate
```

### Forms

```python
from django import forms
from django.contrib.auth.forms import UserChangeForm
from .models import CustomUser

class CustomUserChangeForm(UserChangeForm):
    class Meta(UserChangeForm.Meta):
        model = CustomUser

class ProfileUpdateForm(forms.ModelForm):
    class Meta:
        model = CustomUser
        fields = ['username', 'email', 'phone_number', 'address']

```

### Views

```python
from django.shortcuts import render, redirect, get_object_or_404
from .forms import ProfileUpdateForm
from django.contrib.auth.decorators import login_required
@login_required
def profile(request):
    if request.method == 'POST':
        form = ProfileUpdateForm(request.POST, instance=request.user)
        if form.is_valid():
            form.save()
            return redirect('school_list')
    else:
        form = ProfileUpdateForm(instance=request.user)
    return render(request, 'school/profile.html', {'form': form})
```

### Urls

```python
from django.urls import path
from . import views
urlpatterns=[
       path('profile/', views.profile, name='profile'),

]
```

### Template

**school/profile.html**

```html
<h1>My Profile</h1>
<form method="post">
  {% csrf_token %}
  {{ form.as_p }}
  <button type="submit">Update</button>
</form>
```
