Django Admin - Validating inlines together with main models

后端 未结 1 1138
遇见更好的自我
遇见更好的自我 2021-02-10 18:53

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 severa

1条回答
  •  后悔当初
    2021-02-10 19:46

    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 讨论(0)
提交回复
热议问题