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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:12:02+00:00 2026-06-02T16:12:02+00:00

I have a UserAdmin , and I defined a UserProfileInline like this: from …

  • 0

I have a UserAdmin, and I defined a UserProfileInline like this:

from ...  
from django.contrib.auth.admin import UserAdmin as UserAdmin_

class UserProfileInLine(admin.StackedInline):
    model = UserProfile
    max_num = 1
    can_delete = False
    verbose_name = 'Profile'
    verbose_name_plural = 'Profile'

class UserAdmin(UserAdmin_):
    inlines = [UserProfileInLine]

My UserProfile model has some required fields.

What I want is to force the user not only to enter the username & repeat password, but also to enter at least the required fields so that the UserProfile instance is created and associated to the User that is being added.

If I enter anything in any field of UserProfileInline when creating the user, it validates the form without problem, but if I don’t touch any field, it just creates the User and nothing happens with the UserProfile.

Any thoughts?

  • 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-02T16:12:05+00:00Added an answer on June 2, 2026 at 4:12 pm

    Check recent answer Extending the user profile in Django. Admin creation of users , you need to set the empty_permitted attribute of the form of the inline , to be False. Just like

    class UserProfileForm(forms.ModelForm):
        def __init__(self, *args, **kwargs):
            super(UserProfileForm, self).__init__(*args, **kwargs)
            if self.instance.pk is None:
                self.empty_permitted = False # Here
    
        class Meta:
            model = UserProfile
    
    
    class UserProfileInline(admin.StackedInline):                                     
        form = UserProfileForm  
    

    Another possible solution could be to create your own Formset (that inherits from BaseInlineFormSet), like suggested in this link.

    It could be something like that:

    class UserProfileFormset(BaseInlineFormSet):
        def clean(self):
            for error in self.errors:
                if error:
                    return
            completed = 0
            for cleaned_data in self.cleaned_data:
                # form has data and we aren't deleting it.
                if cleaned_data and not cleaned_data.get('DELETE', False):
                    completed += 1
    
            if completed < 1:
                raise forms.ValidationError('You must create a User Profile.')
    

    Then specify that formset in the InlineModelAdmin:

    class UserProfileInline(admin.StackedInline):
        formset = UserProfileFormset
        ....
    

    The good thing about this second option is that if the UserProfile model doesn’t require any field to be filled, it will still ask for you to enter any data in at least one field. The first mode doesn’t.

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

Sidebar

Related Questions

I have .xml like this: <Type> <Connections> <Conn ServerName=serv1 DataBase=Persons User=admin Pass=123/> <Conn ServerName=serv2
I have to change the is_staff option from views.py file to disabling the Django-admin
So I have several lines in a file that looks like this useradmin:$NT$asdlfkjwaeroisglkwerlkj23424tlj::: useradmin:c2q3r4lsdfk23rlsdfkj3rjsdflk2k23:::
I am using Django 1.3/Python 2.7. My application is using django.contrib.auth for User management.
If I have a directory structure like this: - index.php - public - img
I have 3 classes with the following inheritance structure: <?php class admin { function
I have a django site with a large customer base. I would like to
I have this method: checkFancyBox=function(){ ldValue=LD(user,'admin')+LD(pass,'admin'); if(ldValue<2){ myHashMap[pass.concat(user)]=ldValue; $.fancybox({ content: <span style='color:black'>Wrong username or
I wrote a custom admin class for Users in the Django Admin as follows:
I have an object like follows: @connection.register class User(Document): __collection__ = 'users' __database__ =

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.