from django import forms

# Local
from .models import User


class UserCreationForm(forms.ModelForm):

    class Meta:
        model = User
        fields = '__all__'

    def save(self, commit=True):
        user = super().save(commit=False)
        user.email = self.cleaned_data['person'].email.lower()
        user.set_password(None)
        if commit:
            user.save()
        return user


class UserChangeForm(forms.ModelForm):

    class Meta:
        model = User
        fields = '__all__'

from django import forms

# Local
from .models import User


class UserCreationForm(forms.ModelForm):

    class Meta:
        model = User
        fields = '__all__'

    def save(self, commit=True):
        user = super().save(commit=False)
        user.email = self.cleaned_data['person'].email.lower()
        user.name = self.cleaned_data['name'].name
        user.set_password(None)
        if commit:
            user.save()
        return user


class UserChangeForm(forms.ModelForm):

    class Meta:
        model = User
        fields = '__all__'

Create user name on Admin form create
Create user name on Admin form create

  from django import forms
  
  # Local
  from .models import User
  
  
  class UserCreationForm(forms.ModelForm):
  
      class Meta:
          model = User
          fields = '__all__'
  
      def save(self, commit=True):
          user = super().save(commit=False)
          user.email = self.cleaned_data['person'].email.lower()
+         user.name = self.cleaned_data['name'].name
          user.set_password(None)
          if commit:
              user.save()
          return user
  
  
  class UserChangeForm(forms.ModelForm):
  
      class Meta:
          model = User
          fields = '__all__'
  
Create user name on Admin form create
## Code Before:
from django import forms

# Local
from .models import User


class UserCreationForm(forms.ModelForm):

    class Meta:
        model = User
        fields = '__all__'

    def save(self, commit=True):
        user = super().save(commit=False)
        user.email = self.cleaned_data['person'].email.lower()
        user.set_password(None)
        if commit:
            user.save()
        return user


class UserChangeForm(forms.ModelForm):

    class Meta:
        model = User
        fields = '__all__'

## Instruction:
Create user name on Admin form create
## Code After:
from django import forms

# Local
from .models import User


class UserCreationForm(forms.ModelForm):

    class Meta:
        model = User
        fields = '__all__'

    def save(self, commit=True):
        user = super().save(commit=False)
        user.email = self.cleaned_data['person'].email.lower()
        user.name = self.cleaned_data['name'].name
        user.set_password(None)
        if commit:
            user.save()
        return user


class UserChangeForm(forms.ModelForm):

    class Meta:
        model = User
        fields = '__all__'
