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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:35:37+00:00 2026-05-23T03:35:37+00:00

Forgive me if this has been answered before, I couldn’t find an answer where

  • 0

Forgive me if this has been answered before, I couldn’t find an answer where the validation depended on the aggregate of inline forms.

Little background: I’m doing a site for an insurance broker which has ‘Policies’ and a ‘Total Commission’ of that policy. There are also ‘Resellers’ which are added to the ‘Policy’ along with a commission which goes to them (can have any number of resellers). The total commission between the resellers has to be less than the total commission.

I have an admin.ModelForm for a policy, and below I have a admin.InlineTabular which can have multiple resellers through the ‘Add’ button and this all works perfectly.

However, I can’t seem to figure out how to do validation on them, so that I can basically add up all the commissions and then if it is greater than the total commission throw a ValidationError.

I’ve tried clean() but don’t know how to access the InlineTabular cleaned data if it is even available!

Thanks in advance for any help!

Thomas

  • 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-23T03:35:38+00:00Added an answer on May 23, 2026 at 3:35 am

    I know the question was asked a long time ago, but since I struggled with the same problem, I think it might be usefull.

    The key here is to define a custom formset to embed into the tabular admin form, then to override the formset clean’s method.

    Here’s an example : a composition is made of composition_elements, each composition_element has a percent field, and I want to validate that the total percent is equal to 100.

    from django import forms
    from django.forms.models import BaseInlineFormSet
    from django.core.exceptions import ValidationError
    from django.utils.translation import ugettext_lazy as _
    from django.contrib import admin
    from .models import Composition, CompositionElement
    
    class CompositionElementFormSet(BaseInlineFormSet):
        '''
        Validate formset data here
        '''
        def clean(self):
            super(CompositionElementFormSet, self).clean()
    
            percent = 0
            for form in self.forms:
                if not hasattr(form, 'cleaned_data'):
                    continue
                data = form.cleaned_data
                percent += data.get('percent', 0)
    
            if percent != 100:
                raise ValidationError(_('Total of elements must be 100%%. Current : %(percent).2f%%') % {'percent': percent})
    
    class CompositionElementAdmin(admin.TabularInline):
        model = CompositionElement
        formset = CompositionElementFormSet
    
    class CompositionAdmin(admin.ModelAdmin):
        inlines = (CompositionElementAdmin,)
    
    admin.site.register(Composition, CompositionAdmin)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Forgive me if this has been addressed before, couldn't find anything. I am animating
If this has been asked before please forgive me, I could not find it.
I am sure that the answer to this has been posted before. Forgive me
Please forgive me if this question has been answered - I searched and couldn't
Please forgive me if this has been answered before. I'm looking for some advice
Forgive me if this has been asked before, I'm just unable to find an
Forgive me if this has been asked repeatedly, but I couldn't find an example
Forgive me if this has been asked before, but I was unable to find
Forgive me if this has been asked before; I did a search but couldn't
Forgive me if this has already been asked, I couldn't find it. I have

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.