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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:23:54+00:00 2026-05-23T18:23:54+00:00

I have quite a complex validation requirement, and I cannot get Django admin to

  • 0

I have quite a complex validation requirement, and I cannot get Django admin to satisfy it.

I have a main model (django.contrib.auth.models.User) and several models which look like

class SomeProfile(models.Model):
    user = models.OneToOneField(User)
    # more fields

I want to check that, if the user belongs to some group, then it has the corresponding profile. So if user is in group Foo he should have a non empty FooProfile.

Where do I put this validation rule? I cannot put it in the model. Indeed, the user is not created yet when the form is validated, hence I cannot access his groups. So I need to resort to form validation. This is what I put:

class UserAdminForm(forms.ModelForm):
    """
    A custom form to add validation rules which cannot live in the
    model. We check that users belonging to various groups actually
    have the corresponding profiles.
    """
    class Meta:
        model = User

    def clean(self):
        # Here is where I would like to put the validation

class FooInline(admin.TabularInline):
    model = FooProfile
    max_num = 1


class UserAdmin(admin.ModelAdmin):
    model = User
    form = UserAdminForm
    inlines = [FooInline]

admin.site.register(User, UserAdmin)

My problem is that inside UserAdminForm.clean() I do not have access to the data posted inside the inlines. So I can tell whether the user is in group Foo by inspecting self.cleaned_data['groups'], but I have no way to tell whether a FooProfile was transmitted.

How do I check this validation requirement?

Edit:

I try to explain the issue better, because there has been a misunderstading in an answer.

I have an issue when I create a new user. The fact is that the profiles are mandatory (according to the groups). Say an admin creates a new user; then I have to add inlines in the admin form for the various GroupProfiles.

How do I check that the right profiles are not null? I cannot use the clean() method of the User model, because in there I cannot check what groups the user belongs to: it has not been created yet.

I can only access the information about the groups in the clean() method of the form – but there I do not have the information about the profiles, since this information is submitted trhough inlines.

  • 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-23T18:23:55+00:00Added an answer on May 23, 2026 at 6:23 pm

    1

    well i have been looking around, how all this stuff works, and i found one question very similar here.

    2

    There are one way to get all the data at the same time maybe with this you can find the answer to your problem

    class UserAdminForm(forms.ModelForm):
        """
        A custom form to add validation rules which cannot live in the
        model. We check that users belonging to various groups actually
        have the corresponding profiles.
        """
        class Meta:
            model = User
    
        def clean(self):
            self.data # <--here is all the data of the request
            self.data['groups']
            self.data['profile_set-0-comments'] # some field
            # some validations
            
            return self.cleaned_data
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a complex user model with a validation method before_validation_on_update :geocode_places This validation
I have a quite complex class hierarchy in which the classes are cross-like depending
We currently have a quite complex business application that contains a huge lot of
I hope I will find a help here. I have a quite complex MVC
I have been playing around with a quite complex SQL Statement for a few
I have a quite complex form that presents an option to run a script
I have a ListView with quite high rows. The rows have quite complex layouts,
I have an SWT application which is quite complex at the moment. And I
I have quite a complex MySQL query with a problem but I have narrowed
I have a 3rd party control that is quite complex and takes some time

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.