2.3 KiB
title, description, date, template, about
title | description | date | template | about |
---|---|---|---|---|
Forms | Centurion ERP Forms development documentation | 2024-07-14 | project.html | https://gitlab.com/nofusscomputing/infrastructure/configuration-management/centurion_erp |
Forms are used within Centurion ERP as the method to display the data from the database. Along with that they are designed to sanitise the user entered data.
Requirements
All forms must meet the following requirements:
-
is defined as a class
-
inherits from
core.forms.common.CommonModelForm
-
contains a
Meta
sub-class with following parameters:-
fields
-
model
-
-
Any additional filtering is done as part of an
__init__
method that also calls the super-class__init__
first- Any filtering of a fields
queryset
is to filter the existingqueryset
not redefine it. i.e.field[<field name>].queryset = field[<field name>].queryset.filter()
- Any filtering of a fields
-
validating fields where the validation requires access to multiple fields is done inside the form class using function
clean
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
Details Form
A details form is for the display of a models data. This form should inherit from a base form and contain any additional fields as is required for the display of the models data. Additional requirements are as follows:
-
tab
is defined as adict
within the class. See Template. -
There is an
__init__
class defined that sets up the additional fields.!!! danger "Requirement" Ensure that there is a call to the super-class
__init__
method so that the form is correctly initialised. i.e.super().__init__(*args, **kwargs)
Abstract Classes
The following abstract classes exist for a forms inheritance: