title: Django Admin - Validating inlines together with main models
body: <p>I have quite a complex validation requirement, and I cannot get Django admin to satisfy it.</p>
  
  <p>I have a main model (<code>django.contrib.auth.models.User</code>) and several models which look like</p>
  
  <pre><code>class SomeProfile(models.Model):
      user = models.OneToOneField(User)
      # more fields
  </code></pre>
  
  <p>I want to check that, if the user belongs to some group, then it has the corresponding profile. So if user is in group <code>Foo</code> he should have a non empty <code>FooProfile</code>.</p>
  
  <p>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:</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>My problem is that inside <code>UserAdminForm.clean()</code> 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 <code>self.cleaned_data['groups']</code>, but I have no way to tell whether a <code>FooProfile</code> was transmitted.</p>
  
  <blockquote>
    <p>How do I check this validation requirement?</p>
  </blockquote>
  
  <p><strong>Edit:</strong></p>
  
  <p>I try to explain the issue better, because there has been a misunderstading in an answer.</p>
  
  <p>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.</p>
  
  <p>How do I check that the right profiles are not null? I cannot use the <code>clean()</code> method of the <code>User</code> model, because in there I cannot check what groups the user belongs to: it has not been created yet.</p>
  
  <p>I can only access the information about the groups in the <code>clean()</code> method of the form - but there I do not have the information about the profiles, since this information is submitted trhough inlines.</p>