old_contents: from django.contrib.auth.forms import UserCreationForm
  from profiles.models import Profile
  
  
  class RegistrationForm(UserCreationForm):
      class Meta(UserCreationForm.Meta):
          fields = ("username", "email")
          model = Profile
  
new_contents: from django import forms
  from django.contrib.auth.forms import UserCreationForm
  
  from profiles.models import Profile
  
  
  class RegistrationForm(UserCreationForm):
      class Meta(UserCreationForm.Meta):
          fields = ("username", "email")
          model = Profile
  
  
      def clean_username(self):
          # Since User.username is unique, this check is redundant,
          # but it sets a nicer error message than the ORM. See #13147.
          username = self.cleaned_data["username"]
          try:
              Profile._default_manager.get(username=username)
          except Profile.DoesNotExist:
              return username
          raise forms.ValidationError(
              self.error_messages['duplicate_username'],
              code='duplicate_username',
          )
subject: Fix clean_username method