1

I'm trying to make a form for a service providers booking app as part of a project. I'm just wondering can I change the default "Username" field in Django forms to "Job Title". Here is my current "Forms.py file.

from django import forms
from django.contrib.auth.models import User
from django.contrib.auth.forms import UserCreationForm
from .models import Profile


class UserRegisterForm(UserCreationForm):
    email = forms.EmailField()

    class Meta:
        model = User
        fields = ('username', 
                  'email', 
                  'first_name',
                  'last_name',
                  'password1', 
                  'password2'
            )

    def save(self, commit=True):
        user = super(UserRegisterForm, self).save(commit=False)
        user.first_name = cleaned_data['first_name']
        user.last_name = cleaned_data['last_name']
        user.email = cleaned_data['email']

        if commit:
            user.save()

        return user
dirkgroten
  • 20,112
  • 2
  • 29
  • 42
  • 2
    What do you mean "change to job title"? If you're using the default `django.contrib.auth.models.User` model, then `username` is a mandatory field, and must be unique. You can **add** other fields to your form (e.g. a `job_title` field) like any other form, but you'll need a model to save it to. – dirkgroten Mar 25 '20 at 10:35
  • 2
    If you need to change the `User` model, read [this](https://docs.djangoproject.com/en/3.0/topics/auth/customizing/#extending-the-existing-user-model) and [this](https://docs.djangoproject.com/en/3.0/topics/auth/customizing/#substituting-a-custom-user-model). – dirkgroten Mar 25 '20 at 10:37
  • https://stackoverflow.com/questions/2884382/django-form-and-title-property May be this? – Pavel Antspovich Mar 25 '20 at 11:03

0 Answers0