Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7965397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:08:39+00:00 2026-06-04T06:08:39+00:00

I’ve already defined a custom user account that utilizes several built in’s from the

  • 0

I’ve already defined a custom user account that utilizes several built in’s from the auth User model and, using the user link, links these with some additional fields that I needed to register a user on the database.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

relevant from my models.py

# additional model to incorporate our custom fields to the auth user model                                                                                   
class Account(models.Model):
    user = models.OneToOneField(User)      #link (pointer) to the users other information in User model                                                      
    birthdate = models.DateField(blank = True, ) # True makes this field optional                                                                            
    gender = models.CharField(max_length = 1, choices = GENDER_CHOICE, null = True, blank = True)                                                                                    

    def __unicode__(self):            # define a unicode for the user to access                                                                              
        return u'%s %s' % (self.user.first_name, self.user.last_name)   # return first and last name in shell  


# custom form to gather information from the user for a new account                                                                                          
class UserRegistration(UserCreationForm):
#class RegistrationForm(forms.ModelForm):                                                                                                                    
    class Meta:
        model = User
        fields = ("first_name", "last_name", "email", "username", "password1", "password2",)

    # ensures uniqueness of user email addresses when registering                                                                                         
    def clean_email(self):
        print "In custom creation"
        email = self.cleaned_data.get(email = 'email')
        username = self.cleaned_data.get(username = 'username')
        # checks if email address already exists                                                                                                          
        if User.objects.filter(email__iexact = self.cleaned_data['email']):
            print "Email exists"
#           if email and User.objects.filter(email__iexact = email).exclude(username=username).exists():                                                     
                raise forms.ValidationError(u'Email Address is currently used by another user.')
        return email

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

relevant from views.py

def Main(request):
    if request.user.is_authenticated():
        latest_events = Event.objects.all().order_by('-created')[:10] # Returns latest 10 events                                                              
        my_events = Event.objects.filter(creator=request.user)[:10]   # Returns up to 10 events created by current User                                       
        my_calendars = Calendar.objects.filter(creator=request.user)  # Returns all calendars created by the user                                             
        authForm = None
        loginForm = None
        headerType = "header.html"
    else:
        latest_events = None
        my_events = None
        my_calendars = None
        headerType = "header_main.html"

        authForm = UserRegistration(request.POST or None)
        print "Creating account UserRegistration" # TESTING PRINT                                                                                             
        print "User email = %s " %(User._meta.get_field('email'))
        if request.method == 'POST':
            if authForm.is_valid():
                newUser = authForm.save(commit=False)
                newUser.save()
                newUser = authenticate(username=request.POST['username'], password=request.POST['password1'])
                login(request, newUser)

                return HttpResponseRedirect('/signup/')
....
....
more code on success redirection
....
....

~~~~~~~~~~~~~~~~~~~~~~~~~~~

(I hope I didn’t post too much code, just wanted to be thorough)

As you can see there are a few commented out attempts I’ve made recently. I tried using thee built in RegistrationFormUniqueForm() by downloading ‘registration’ but I don’t actually want to make a new registration form since I already have a working one.

I moved on to trying another suggestion, the code under the comment

# custom form to display additional sign up information

When I tried registering a new user with an already registered email it did not throw any error and allowed the registration. I also tried changing the users email and it allowed the change to an already taken email with no objection.

Can anyone suggest a method for making user registration maintain a unique lock on each individual attempting to register with an email address that may already be taken? As well as preventing them from changing their email to one that is taken by a current user?

Thanks in advance.

EDIT: I made changes to the Models registration form def clean_email() and the def in views to reflect what I currently have that still does not work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T06:08:40+00:00Added an answer on June 4, 2026 at 6:08 am

    The indentation of your clean_email methods is wrong for both forms. At the moment, they are methods of the Meta class, so will never be called. For example, the registration form should be:

    class RegistrationForm(UserCreationForm):
    #class RegistrationForm(forms.ModelForm):                                                                                                                    
        class Meta:
            model = User
            fields = ("first_name", "last_name", "email", "username", "password1", "password2",)
    
        def clean_email(self):
            """ensures uniqueness of user email addresses when registering"""
            email = self.cleaned_data.get('email')
    

    This might not be the real problem — it’s easy to get the indentation wrong when pasting code into stack overflow. If that’s the case, I’ll delete the answer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am doing a simple coin flipping experiment for class that involves flipping a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.