@ -27,6 +27,30 @@ All forms must meet the following requirements:
|
||||
|
||||
- Any filtering of a fields `queryset` is to filter the existing `queryset` not redefine it. i.e. `field[<field name>].queryset = field[<field name>].queryset.filter()`
|
||||
|
||||
- validating fields where the validation requires access to multiple fields is done inside the form class using function `clean`
|
||||
|
||||
``` py
|
||||
|
||||
def clean(self):
|
||||
|
||||
cleaned_data = super().clean()
|
||||
|
||||
# begin example
|
||||
responsible_user = cleaned_data.get("responsible_user")
|
||||
responsible_teams = cleaned_data.get("responsible_teams") example
|
||||
|
||||
|
||||
if not responsible_user and not responsible_teams:
|
||||
|
||||
raise ValidationError('A Responsible User or Team must be assigned.')
|
||||
# end example
|
||||
|
||||
# your validation after `super()` call
|
||||
|
||||
return cleaned_data
|
||||
|
||||
```
|
||||
|
||||
|
||||
## Abstract Classes
|
||||
|
||||
|
@ -33,6 +33,11 @@ All models must meet the following requirements:
|
||||
|
||||
- No `queryset` is to return data that the user has not got access to. _see [queryset()](./api/models/tenancy_object.md#tenancy-object-manager)_
|
||||
|
||||
- Single Field validation is conducted if required.
|
||||
|
||||
!!! danger "Requirement"
|
||||
Multi-field validation, or validation that requires access to multiple fields must be done within the [form class](./forms.md#requirements).
|
||||
|
||||
|
||||
## History
|
||||
|
||||
|
Reference in New Issue
Block a user