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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:57:05+00:00 2026-05-12T07:57:05+00:00

I have the following admin setup so that I can add/edit a user and

  • 0

I have the following admin setup so that I can add/edit a user and their profile at the same time.

class ProfileInline(admin.StackedInline):
    """
    Allows profile to be added when creating user
    """
    model = Profile


class UserProfileAdmin(admin.ModelAdmin):
    """
    Options for the admin interface
    """
    inlines = [ProfileInline]
    list_display = ['edit_obj', 'name', 'username', 'email', 'is_active',
        'last_login', 'delete_obj']
    list_display_links = ['username']
    list_filter = ['is_active']
    fieldsets = (
        (None, {
            'fields': ('first_name', 'last_name', 'email', 'username',
                'is_active', 'is_superuser')}),
        )
    ordering = ['last_name', 'first_name']
    search_fields = ['first_name', 'last_name']

admin.site.register(User, UserProfileAdmin)

The problem is I need two of the fields in the Profile inline form to be required when adding the user. The inline form doesn’t validate unless input is entered. Is there anyway to make the inline required, so that it can’t be left blank?

  • 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-12T07:57:05+00:00Added an answer on May 12, 2026 at 7:57 am

    I took Carl’s advice and made a much better implementation then the hack-ish one I mentioned in my comment to his answer. Here is my solution:

    From my forms.py:

    from django.forms.models import BaseInlineFormSet
    
    
    class RequiredInlineFormSet(BaseInlineFormSet):
        """
        Generates an inline formset that is required
        """
    
        def _construct_form(self, i, **kwargs):
            """
            Override the method to change the form attribute empty_permitted
            """
            form = super(RequiredInlineFormSet, self)._construct_form(i, **kwargs)
            form.empty_permitted = False
            return form
    

    And the admin.py

    class ProfileInline(admin.StackedInline):
        """
        Allows profile to be added when creating user
        """
        model = Profile
        extra = 1
        max_num = 1
        formset = RequiredInlineFormSet
    
    
    class UserProfileAdmin(admin.ModelAdmin):
        """
        Options for the admin interface
        """
        inlines = [ProfileInline]
        list_display = ['edit_obj', 'name', 'username', 'email', 'is_active',
            'last_login', 'delete_obj']
        list_display_links = ['username']
        list_filter = ['is_active']
        fieldsets = (
            (None, {
                'fields': ('first_name', 'last_name', 'email', 'username',
                    'is_active', 'is_superuser')}),
            (('Groups'), {'fields': ('groups', )}),
        )
        ordering = ['last_name', 'first_name']
        search_fields = ['first_name', 'last_name']
    
    
    admin.site.register(User, UserProfileAdmin)
    

    This does exactly what I want, it makes the Profile inline formset validate. So since there are required fields in the profile form it will validate and fail if the required information isn’t entered on the inline form.

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

Sidebar

Ask A Question

Stats

  • Questions 265k
  • Answers 265k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can also tap into the IIS pipeline more directly… May 13, 2026 at 12:31 pm
  • Editorial Team
    Editorial Team added an answer I finally got this working. This was happening because there… May 13, 2026 at 12:31 pm
  • Editorial Team
    Editorial Team added an answer Use socket.BeginSend and socket.BeginReceive. These will spin off seperate threads… May 13, 2026 at 12:31 pm

Related Questions

I installed the Mocha 0.9.7 Rails plug-in using: $ script/plugin install git://github.com/floehopper/mocha.git (Just followed
So let's say I'm using Python 2.5's built-in default sqlite3 and I have a
I have an ASP.NET MVC website and an area project called 'Admin'. So far
I have a scenario where I need to upload a file from one web

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.