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 8055423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:22:50+00:00 2026-06-05T08:22:50+00:00

I am trying to create a form for the user to change their profile

  • 0

I am trying to create a form for the user to change their profile account information on their own. Currently I have it so they can update their first, last and username, gender and ‘birthdate’. The ‘birthdate’ is the only one I can’t get to be not required. Currently my form checks if no input was given in any of the forms fields and will NOT update the users information if no changes are made.

~~Models.py~~

class Account(models.Model):
    user               = models.OneToOneField(User)      #link (pointer) to the users     other information in User model                                        
    birthdate          = models.DateField(blank = True, null = True) # True makes this field optional                                                        
    gender             = models.CharField(max_length = 10, choices = GENDER_CHOICE, null = True, blank = True)
    profilePic         = models.ImageField(upload_to = "profilepics/%Y/%m/%d", default = "profilepics/default.jpg", blank = True)

–Form to gather user setting changes

class EditAccountForm(forms.Form):
    username           = forms.CharField(max_length = 30, required = False)
    first_name         = forms.CharField(max_length = 30, required = False)
    last_name          = forms.CharField(max_length = 30, required = False)
    birthdate          = forms.DateField(widget = SelectDateWidget(required = False, years = range(2022, 1930, -1))) # make birthdate drop down selectable    
    gender             = forms.CharField(max_length = 10, widget=forms.Select(choices = GENDER_CHOICE),)# null = True)                 

~~Views.py

def AccountSettings(request):
    sluggedSettingError = request.GET.get('error', '') # error message with slugged character                                                                
    settingError = sluggedSettingError.replace('-', ' ')
    # form variable may need to be inside below if statement                                                                                                 
    settingForm = EditAccountForm(request.POST or None) # variable is called in edit_user.html                                                               
    if request.method == 'POST':
        if settingForm.is_valid():

            userSettings = request.user.get_profile() # returns the current settings of the users profile 
if request.POST['gender'] == '---':
                print "Gender was not changed"
            else:
                userSettings.gender = request.POST['gender']  # add a check for birthdate submission                                                         
            userSettings.birthdate = settingForm.cleaned_data.get('birthdate')   # currently requires input format YYYY-mm-dd                                
            # check if the first name submission is not changed                                                                                              
            if request.POST['first_name'] == '':
                print "First name not changed"
            else:
                userSettings.user.first_name = request.POST['first_name']
            # check if the last name submission is not changed                                                                                               
            if request.POST['last_name'] == '':
                print "Last name not changed"
            else:
                userSettings.user.last_name = request.POST['last_name']
            # check if the username submission is not changed                                                                                                
            if request.POST['username'] == '':
                print "Username not changed"
            else:
                userSettings.user.username = request.POST['username']
            # check if the ProfilePicture submission is not changed                                                                                          
#                if request.POST['profilePic'] == None:
#                    print "Profile picture not changed"
#                else:
#                    userSettings.profilePic = request.POST['profilePic']
            userSettings.user.save()              # save the changes to the fields in used from the auth library                                             
            userSettings.save()                   # save the altered and unaltered settings                                                                  
            return HttpResponseRedirect('/')
    return render_to_response("user_settings.html", {'settingForm': settingForm, 'settingError': settingError}, context_instance = RequestContext(request))

Is there a way to make the birthdate field not required whilst using the SelectDateWidget() since my current attempt of required = False does not work. Or possibly a better method to allow the user to edit their settings and submit the changes?

  • 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-05T08:22:52+00:00Added an answer on June 5, 2026 at 8:22 am

    I expect your problem derives from the fact that:

    settingForm.cleaned_data.get('birthdate')
    

    won’t return None but hands you an empty string '' which isn’t what the Date or DateTime field expects.

    You should return a NoneType if the user hasn’t actually selected a date.

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

Sidebar

Related Questions

I'm trying to put together a form whereby users can update their 'email address'
I am trying to create a form to allow users to change their password:
I am trying to create a user form that will allow the user to
I'm trying to create a child form that helps the user to enter data
I am trying to create an asp.net web form that allows a user to
I'm trying to create multiple form instances. For example, i have a form1 and
I am trying to create a form which loads upon a user clicking a
I'm trying to create a site where, like Digg, a user can submit a
I currently have a couple of forms that I'm trying to change the button
I'm trying to create a form with a user selected style saved to an

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.