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

  • Home
  • SEARCH
  • 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 7249019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:13:36+00:00 2026-05-28T22:13:36+00:00

Is there an easy way to allow for required profile fields? I am using

  • 0

Is there an easy way to allow for required profile fields?

I am using userena in my current django project. I have a custom profile called UserProfile which has a start_year none-blank, non-null field as defined below.

class UserProfile(UserenaBaseProfile, PybbProfile):
    user = models.OneToOneField(User, unique=True,
                        verbose_name=_('user'),
                        related_name='user_profile')

    start_year = models.IntegerField(max_length=4)

I need this to be filled-in on signup. I created a SignupExtraForm as defined below, to override the default form.

class SignupFormExtra(SignupForm):
    start_year = forms.IntegerField(label=_(u'Initiation Year'),
                            min_value=1800,
                            max_value=datetime.now().year,
                            required=True)

    def save(self):
        new_user = super(SignupFormExtra, self).save()

        new_user_profile = new_user.get_profile()

        new_user_profile.start_year = self.cleaned_data['start_year']
        new_user_profile.save()

        # Userena expects to get the new user from this form, so return the new
        # user.
        return new_user

When I attempt to add a new user thru the now modified form I get the below error:

profile_userprofile.start_year may not be NULL

With the stack trace pointing at new_user = super(SignupFormExtra, self).save()), in the code above.

I think this has to do with the user profile being created and saved before I am able to give it the required data from the form. Is there an easy way of supplying this data to the user_creation process, or delaying the creating of the user profile?

Thanks
Shon

  • 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-05-28T22:13:36+00:00Added an answer on May 28, 2026 at 10:13 pm

    UserProfile is created after the User is saved by a post_save signal. Even if you override it with your own signal, you won’t have access to the form data from there.

    The easiest solution is to just allow start_year to be NULL. It’s not necessary to enforce this at the database level, and you can make the field required in all forms either way:

    start_year = models.IntegerField(max_length=4, blank=False, null=True)
    

    Your custom form already enforces that the field is required, so you’re done.

    UPDATE (from comment)

    Custom form, yes, but you can still use a ModelForm:

    class MyModelForm(forms.ModelForm):
        def __init__(self, *args, **kwargs):
            super(MyModelForm, self).__init__(*args, **kwargs)
            self.fields['start_year'].required = True
    

    UPDATE (again)

    Actually, I didn’t think before my last update. I put blank=False on the start_year field in my example. That will force that the field is required in all ModelForms by default. You don’t need a custom ModelForm at all. However, I left the previous update for posterity.

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

Sidebar

Related Questions

Is there an easy way of using the RegularExpressionValidator control while ignoring white space?
Is there an easy way to allow a user to register as he creates
Is there an easy way, or free library, that will allow you to append
Is there an easy way to do the following: I have an application which
Is there an easy way in Grails to not allow deleting for any Domain
Is there an easy way to iterate over an associative array of this structure
Is there an easy way in C# to create Ordinals for a number? For
Is there an easy way to produce MSDN-style documentation from the Visual Studio XML
Is there an easy way to avoid dealing with text encoding problems?
Is there an easy way to tell if a ruby script is already running

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.